1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
package tests
import (
"fmt"
r "gopkg.in/rethinkdb/rethinkdb-go.v6"
)
// Create a table named "table" with the default settings.
func ExampleTerm_TableCreate() {
// Setup database
r.DB("examples").TableDrop("table").Run(session)
response, err := r.DB("examples").TableCreate("table").RunWrite(session)
if err != nil {
r.Log.Fatalf("Error creating table: %s", err)
}
fmt.Printf("%d table created", response.TablesCreated)
// Output:
// 1 table created
}
// Create a simple index based on the field name.
func ExampleTerm_IndexCreate() {
// Setup database
r.DB("examples").TableDrop("table").Run(session)
r.DB("examples").TableCreate("table").Run(session)
response, err := r.DB("examples").Table("table").IndexCreate("name").RunWrite(session)
if err != nil {
r.Log.Fatalf("Error creating index: %s", err)
}
fmt.Printf("%d index created", response.Created)
// Output:
// 1 index created
}
// Create a compound index based on the fields first_name and last_name.
func ExampleTerm_IndexCreate_compound() {
// Setup database
r.DB("examples").TableDrop("table").Run(session)
r.DB("examples").TableCreate("table").Run(session)
response, err := r.DB("examples").Table("table").IndexCreateFunc("full_name", func(row r.Term) interface{} {
return []interface{}{row.Field("first_name"), row.Field("last_name")}
}).RunWrite(session)
if err != nil {
r.Log.Fatalf("Error creating index: %s", err)
}
fmt.Printf("%d index created", response.Created)
// Output:
// 1 index created
}
|