Created
February 28, 2016 08:47
-
-
Save axelgenus/8170f009175cdd00e419 to your computer and use it in GitHub Desktop.
This file contains hidden or 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" | |
| ) | |
| type Writer struct { | |
| ID string `gorethink:"id,omitempty"` | |
| Name string `gorethink:"name"` | |
| } | |
| type Book struct { | |
| ID string `gorethink:"id,omitempty"` | |
| Title string `gorethink:"title"` | |
| Author *Writer `gorethink:"author"` | |
| } | |
| func main() { | |
| tolkien := &Writer{ Name: "JRR Tolkien" } | |
| book1 := &Book{ Title: "The Hobbit", Author: tolkien } | |
| book2 := &Book{ Title: "The Lord of the Rings", Author: tolkien } | |
| s, err := r.Connect(r.ConnectOpts{ Address: "172.17.0.2:28015" }) | |
| if err != nil { | |
| panic(err) | |
| } | |
| r.DB("test").TableDrop("writers").Exec(s) | |
| r.DB("test").TableCreate("writers").Exec(s) | |
| r.DB("test").TableDrop("books").Exec(s) | |
| r.DB("test").TableCreate("books").Exec(s) | |
| if err := r.DB("test").Table("writers").Insert(tolkien).Exec(s); err != nil { | |
| panic(err) | |
| } | |
| if err := r.DB("test").Table("books").Insert(book1).Exec(s); err != nil { | |
| panic(err) | |
| } | |
| if err := r.DB("test").Table("books").Insert(book2).Exec(s); err != nil { | |
| panic(err) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment