File: example_query_table_test.go

package info (click to toggle)
golang-gopkg-dancannon-gorethink.v1 1.4.1-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 764 kB
  • sloc: makefile: 3
file content (57 lines) | stat: -rw-r--r-- 1,454 bytes parent folder | download | duplicates (4)
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
package gorethink

import (
	"fmt"
)

// Create a table named "table" with the default settings.
func ExampleTerm_TableCreate() {
	// Setup database
	DB("examples").TableDrop("table").Run(session)

	response, err := DB("examples").TableCreate("table").RunWrite(session)
	if err != nil {
		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
	DB("examples").TableDrop("table").Run(session)
	DB("examples").TableCreate("table").Run(session)

	response, err := DB("examples").Table("table").IndexCreate("name").RunWrite(session)
	if err != nil {
		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
	DB("examples").TableDrop("table").Run(session)
	DB("examples").TableCreate("table").Run(session)

	response, err := DB("examples").Table("table").IndexCreateFunc("full_name", func(row Term) interface{} {
		return []interface{}{row.Field("first_name"), row.Field("last_name")}
	}).RunWrite(session)
	if err != nil {
		Log.Fatalf("Error creating index: %s", err)
	}

	fmt.Printf("%d index created", response.Created)

	// Output:
	// 1 index created
}