This repository has been archived by the owner on Jan 18, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1e7ae8b
commit 5f43949
Showing
3 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package test | ||
|
||
import ( | ||
"testing" | ||
|
||
_ "gopkg.in/istreamdata/orientgo.v2/obinary" | ||
) | ||
|
||
// Dial example | ||
func TestDial(t *testing.T) { | ||
client, err := orient.Dial("127.0.0.1:2424") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
admin, err := client.Auth(dbUser, dbPass) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// There are 2 options | ||
// 1. orient.Persistent - represents on-disk database | ||
// 2. orient.Volatile - represents in-memory database | ||
ok, err := admin.DatabaseExists(dbName, orient.Persistent) | ||
if err != nil { | ||
t.Fatal(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(dbName, orient.GraphDB, orient.Persistent) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
} | ||
|
||
// Open wanted database & operate further | ||
database, err := client.Open(dbName, orient.GraphDB, dbUser, dbPass) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer database.Close() | ||
} |