-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_test.go
More file actions
50 lines (41 loc) · 1.47 KB
/
Copy pathexample_test.go
File metadata and controls
50 lines (41 loc) · 1.47 KB
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
package pluginsdk
import "fmt"
func ExampleSetColumns() {
var asset Asset
_ = SetColumns(&asset, []Column{
{Name: "id", DataType: "bigint", Nullable: false, PrimaryKey: true},
{Name: "email", DataType: "text", Nullable: true},
})
fmt.Println(asset.Schema["columns"])
// Output:
// [{"column_name":"id","data_type":"bigint","is_nullable":false,"is_primary_key":true},{"column_name":"email","data_type":"text","is_nullable":true}]
}
// Embed Column to add source-specific fields.
func ExampleSetColumns_extend() {
type clickhouseColumn struct {
Column
Codec string `json:"codec,omitempty"`
}
var asset Asset
_ = SetColumns(&asset, []clickhouseColumn{
{Column: Column{Name: "id", DataType: "UInt64"}, Codec: "ZSTD"},
})
fmt.Println(asset.Schema["columns"])
// Output:
// [{"column_name":"id","data_type":"UInt64","is_nullable":false,"codec":"ZSTD"}]
}
// Pass a []any to mix a plain Column with an extended one in a single call.
func ExampleSetColumns_mix() {
type clickhouseColumn struct {
Column
Codec string `json:"codec,omitempty"`
}
var asset Asset
_ = SetColumns(&asset, []any{
Column{Name: "id", DataType: "UInt64", PrimaryKey: true},
clickhouseColumn{Column: Column{Name: "created_at", DataType: "DateTime"}, Codec: "ZSTD"},
})
fmt.Println(asset.Schema["columns"])
// Output:
// [{"column_name":"id","data_type":"UInt64","is_nullable":false,"is_primary_key":true},{"column_name":"created_at","data_type":"DateTime","is_nullable":false,"codec":"ZSTD"}]
}