forked from piotrkowalczuk/pqt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema.go
53 lines (43 loc) · 933 Bytes
/
schema.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
45
46
47
48
49
50
51
52
53
package pqt
// Schema ...
type Schema struct {
Name string
IfNotExists bool
Tables []*Table
Functions []*Function
Types []Type
}
// NewSchema ...
func NewSchema(name string, opts ...SchemaOption) *Schema {
s := &Schema{
Name: name,
}
for _, opt := range opts {
opt(s)
}
return s
}
// AddTable ...
func (s *Schema) AddTable(t *Table) *Schema {
if s.Tables == nil {
s.Tables = make([]*Table, 0, 1)
}
t.Schema = s
s.Tables = append(s.Tables, t)
return s
}
func (s *Schema) AddFunction(f *Function) *Schema {
if s.Functions == nil {
s.Functions = make([]*Function, 0, 1)
}
s.Functions = append(s.Functions, f)
return s
}
// SchemaOption configures how we set up a schema.
type SchemaOption func(*Schema)
// WithSchemaIfNotExists is schema option that sets IfNotExists flag to true.
func WithSchemaIfNotExists() SchemaOption {
return func(s *Schema) {
s.IfNotExists = true
}
}