/
example_writer_test.go
44 lines (39 loc) · 1.3 KB
/
example_writer_test.go
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
package main
func ExampleSimpleWriter_WriteRows() {
writer := &SimpleWriter{}
rows := make([]*map[string]interface{}, 0)
rows = append(rows, &map[string]interface{}{"name": "one"})
rows = append(rows, &map[string]interface{}{"id": int(123)})
rows = append(rows, &map[string]interface{}{"value": int64(456)})
rows = append(rows, &map[string]interface{}{"amount": 1.23})
rows = append(rows, &map[string]interface{}{"chars": []uint8{0x26, 0x23, 0x29}})
rows = append(rows, &map[string]interface{}{"nulled": nil})
rows = append(rows, &map[string]interface{}{"strange": uintptr(1)})
writer.WriteRows("some_table", []string{}, rows)
// Output:
// some_table
// name = one;||
// id = 123;||
// value = 456;||
// amount = 1.230000;||
// chars = &#);||
// nulled = NULL;||
// strange = UNDEFINED;||
}
func ExampleSimpleWriter_WriteDDL() {
writer := &SimpleWriter{}
ddl := "CREATE TABLE `some_table` (\n"
ddl += " `id` bigint(20) NOT NULL,\n"
ddl += " `name` varchar(100) NOT NULL,\n"
ddl += " PRIMARY KEY (`id`),\n"
ddl += " UNIQUE INDEX `name` (`name`)\n"
ddl += ");"
writer.WriteDDL("some_table", ddl)
// Output:
// CREATE TABLE `some_table` (
// `id` bigint(20) NOT NULL,
// `name` varchar(100) NOT NULL,
// PRIMARY KEY (`id`),
// UNIQUE INDEX `name` (`name`)
// );
}