Skip to content

Instantly share code, notes, and snippets.

@axelgenus
Created February 28, 2016 08:47
Show Gist options
  • Select an option

  • Save axelgenus/8170f009175cdd00e419 to your computer and use it in GitHub Desktop.

Select an option

Save axelgenus/8170f009175cdd00e419 to your computer and use it in GitHub Desktop.
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