MCPcopy
hub / github.com/dropbox/godropbox / Example

Function Example

database/sqlbuilder/example_test.go:5–38  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3import "fmt"
4
5func Example() {
6 t1 := NewTable(
7 "parent_prefix",
8 IntColumn("ns_id", NotNullable),
9 IntColumn("hash", NotNullable),
10 StrColumn("prefix",
11 UTF8,
12 UTF8CaseInsensitive,
13 NotNullable))
14
15 t2 := NewTable(
16 "sfj",
17 IntColumn("ns_id", NotNullable),
18 IntColumn("sjid", NotNullable),
19 StrColumn("filename",
20 UTF8,
21 UTF8CaseInsensitive,
22 NotNullable))
23
24 ns_id1 := t1.C("ns_id")
25 prefix := t1.C("prefix")
26 ns_id2 := t2.C("ns_id")
27 sjid := t2.C("sjid")
28 filename := t2.C("filename")
29
30 in := []int32{1, 2, 3}
31 join := t2.LeftJoinOn(t1, Eq(ns_id1, ns_id2))
32 q := join.Select(ns_id2, sjid, prefix, filename).Where(
33 And(EqL(ns_id2, 456), In(sjid, in)))
34 text, _ := q.String("shard1")
35 fmt.Println(text)
36 // Output:
37 // SELECT `sfj`.`ns_id`,`sfj`.`sjid`,`parent_prefix`.`prefix`,`sfj`.`filename` FROM `shard1`.`sfj` LEFT JOIN `shard1`.`parent_prefix` ON `parent_prefix`.`ns_id`=`sfj`.`ns_id` WHERE (`sfj`.`ns_id`=456 AND `sfj`.`sjid` IN (1,2,3))
38}

Callers

nothing calls this directly

Calls 12

CMethod · 0.95
LeftJoinOnMethod · 0.95
NewTableFunction · 0.85
IntColumnFunction · 0.85
StrColumnFunction · 0.85
EqFunction · 0.85
AndFunction · 0.85
EqLFunction · 0.85
InFunction · 0.85
WhereMethod · 0.65
SelectMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected