Created
February 21, 2014 09:17
-
-
Save taichi/9131170 to your computer and use it in GitHub Desktop.
RethinkDB and golang
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
package main | |
import ( | |
r "github.com/dancannon/gorethink" | |
"log" | |
) | |
type upd struct { | |
Zzz []string `gorethink:"zzz"` | |
} | |
func main() { | |
session, err := r.Connect(map[string]interface{}{ | |
"address": "rethinkdb:28015", | |
"database": "test", | |
}) | |
if err != nil { | |
log.Fatalln(err) | |
} | |
res1, e1 := r.Table("tv_shows").Insert(map[string]interface{}{ | |
"name": "aaa", | |
"zzz": []string{"ccc", "ddd"}, | |
}).RunWrite(session) | |
if e1 != nil { | |
log.Fatalln(e1) | |
} | |
term := r.Table("tv_shows").Get(res1.GeneratedKeys[0]) | |
q := map[string]r.RqlTerm{"zzz": r.Row.Field("zzz").Append("ppp1")} | |
_, e2 := term.Update(q).RunWrite(session) | |
if e2 != nil { | |
log.Fatalln(e2) | |
} | |
_, e3 := r.Table("tv_shows").Get(res1.GeneratedKeys[0]).Delete().RunWrite(session) | |
if e3 != nil { | |
log.Fatalln(e3) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment