-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_schema.go
52 lines (42 loc) · 1.07 KB
/
create_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
package sqls
import (
"strings"
)
type createSchemaStatement struct {
schema []string
ifNotExists bool
}
type createSchemaBuilder struct {
builder *sqlBuilder
statement *createSchemaStatement
}
func newCreateSchemaBuilder() *createSchemaBuilder {
builder := &createSchemaBuilder{}
builder.builder = newSqlBuilder()
builder.statement = &createSchemaStatement{}
return builder
}
func CREATE_SCHEMA(v string) *createSchemaBuilder {
s := newCreateSchemaBuilder()
s.statement.schema = append(s.statement.schema, v)
return s
}
func (s *createSchemaBuilder) IF_NOT_EXISTS() *createSchemaBuilder {
s.statement.ifNotExists = true
return s
}
func (s *createSchemaBuilder) Param(v any) string {
return s.builder.Param(v)
}
func (s *createSchemaBuilder) String() string {
var sqlString string
keyword := "CREATE SCHEMA"
if s.statement.ifNotExists {
keyword += " IF NOT EXISTS"
}
sqlString += s.builder.join(keyword, "", s.statement.schema, "", "")
return strings.Trim(sqlString, " ")
}
func (s *createSchemaBuilder) Params() []any {
return s.builder.Params(s.String())
}