summaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorMarvin Killing <marvinkilling@gmail.com>2013-07-13 15:16:20 +0200
committerMarvin Killing <marvinkilling@gmail.com>2013-07-13 15:16:20 +0200
commit57acf13beb0d6cf9f7ff4e2d238bdd20d40bdd8c (patch)
tree0255887528e9a1f3b7a0bcb474d412f2f33e2711 /README.md
parentc5c33d75f48fc82fad061feb9286fec42a326fa7 (diff)
downloadejdb-57acf13beb0d6cf9f7ff4e2d238bdd20d40bdd8c.tar.gz
ejdb-57acf13beb0d6cf9f7ff4e2d238bdd20d40bdd8c.tar.bz2
ejdb-57acf13beb0d6cf9f7ff4e2d238bdd20d40bdd8c.zip
add golang one snippet intro to root README
Diffstat (limited to 'README.md')
-rw-r--r--README.md57
1 files changed, 57 insertions, 0 deletions
diff --git a/README.md b/README.md
index 3aa0be0..5b68f3f 100644
--- a/README.md
+++ b/README.md
@@ -715,6 +715,63 @@ db:close()
* **[Lua binding](https://github.com/Softmotions/ejdb/blob/master/luaejdb/README.md)**
+EJDB Go binding
+==================================
+
+One snippet intro
+-----------------------------------
+
+~~~~~~
+package ejdbtutorial
+
+import (
+ "fmt"
+ "github.com/mkilling/ejdb/goejdb"
+ "labix.org/v2/mgo/bson"
+ "os"
+)
+
+func main() {
+ // Create a new database file and open it
+ jb, err := goejdb.Open("addressbook", JBOWRITER | JBOCREAT | JBOTRUNC)
+ if err != nil {
+ os.Exit(1)
+ }
+ // Get or create collection 'contacts'
+ coll, _ := jb.CreateColl("contacts", nil)
+
+ // Insert one record:
+ // JSON: {'name' : 'Bruce', 'phone' : '333-222-333', 'age' : 58}
+ rec := map[string]interface{} {"name" : "Bruce", "phone" : "333-222-333", "age" : 58}
+ bsrec, _ := bson.Marshal(rec)
+ coll.SaveBson(bsrec)
+ fmt.Printf("\nSaved Bruce")
+
+ // Now execute query
+ res, _ := coll.Find(`{"name" : {"$begin" : "Bru"}}`) // Name starts with 'Bru' string
+ fmt.Printf("\n\nRecords found: %d\n", len(res))
+
+ // Now print the result set records
+ for _, bs := range res {
+ var m map[string]interface{}
+ bson.Unmarshal(bs, &m)
+ fmt.Println(m)
+ }
+
+ // Close database
+ jb.Close()
+}
+~~~~~~
+
+You can save this code in `ejdbtutorial.go` And build:
+
+
+```sh
+go build ejdbtutorial.go
+./ejdbtutorial
+```
+
+
EJDB C Library
==================================