Skip to content
This repository has been archived by the owner on Jan 18, 2025. It is now read-only.

Commit

Permalink
Add database Dial example
Browse files Browse the repository at this point in the history
  • Loading branch information
ernestas-poskus committed Jan 6, 2016
1 parent 1e7ae8b commit 1b2e521
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ You are welcome to initiate pull request and suggest a more user-friendly API. W

3) `go test -v ./...`

## Examples

Dial example - dial_example_test.go

## LICENSE

The MIT License
52 changes: 52 additions & 0 deletions dial_example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package orient_test

import (
"testing"

"gopkg.in/istreamdata/orientgo.v2"
_ "gopkg.in/istreamdata/orientgo.v2/obinary"
)

// Dial example
func TestDial(t *testing.T) {
addr, _ := SpinOrientServer(t)
testDbName := "test_db_example"
testDbUser := "root"
testDbPass := "root"

client, err := orient.Dial(addr)
if err != nil {
panic(err)
}

admin, err := client.Auth(testDbUser, testDbPass)
if err != nil {
panic(err)
}

// There are 2 options
// 1. orient.Persistent - represents on-disk database
// 2. orient.Volatile - represents in-memory database
ok, err := admin.DatabaseExists(testDbName, orient.Persistent)
if err != nil {
panic(err)
}

// If database does not exist let's create it
if !ok {
// There are 2 options
// 1. orient.GraphDB - graph database
// 2. orient.DocumentDB - document database
err = admin.CreateDatabase(testDbName, orient.GraphDB, orient.Persistent)
if err != nil {
panic(err)
}
}

// Open wanted database & operate further
database, err := client.Open(testDbName, orient.GraphDB, testDbUser, testDbPass)
if err != nil {
panic(err)
}
defer database.Close()
}

0 comments on commit 1b2e521

Please sign in to comment.