-
-
Notifications
You must be signed in to change notification settings - Fork 180
Simple Example
m4ng0squ4sh edited this page Jan 10, 2015
·
16 revisions
package main
import (
"fmt"
r "github.com/dancannon/gorethink"
)
var session *r.Session
func init() {
var err error
session, err = r.Connect(r.ConnectOpts{
Address: "localhost:28015",
Database: "test",
})
if err != nil {
fmt.Println(err)
return
}
}
// Struct tags are used to map struct fields to fields in the database
type Person struct {
Id string `gorethink:"id,omitempty"`
Name string `gorethink:"name"`
Place string `gorethink:"place"`
}
func main() {
// fetch all records from "persons" table
rows, _ := r.Table("persons").Run(session)
var persons []Person
_ := rows.All(&persons)
fmt.Println(persons)
}