-
Notifications
You must be signed in to change notification settings - Fork 12
/
options.go
130 lines (110 loc) · 2.79 KB
/
options.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package sqlize
import (
sql_templates "github.com/sunary/sqlize/sql-templates"
)
type sqlizeOptions struct {
migrationFolder string
migrationUpSuffix string
migrationDownSuffix string
migrationTable string
sqlTag string
dialect sql_templates.SqlDialect
lowercase bool
pluralTableName bool
generateComment bool
ignoreFieldOrder bool
}
type funcSqlizeOption struct {
f func(*sqlizeOptions)
}
func (fmo *funcSqlizeOption) apply(do *sqlizeOptions) {
fmo.f(do)
}
func newFuncSqlizeOption(f func(*sqlizeOptions)) *funcSqlizeOption {
return &funcSqlizeOption{
f: f,
}
}
// SqlizeOption ...
type SqlizeOption interface {
apply(*sqlizeOptions)
}
// WithMigrationFolder ...
func WithMigrationFolder(path string) SqlizeOption {
return newFuncSqlizeOption(func(o *sqlizeOptions) {
o.migrationFolder = path
})
}
// WithMigrationSuffix ...
func WithMigrationSuffix(upSuffix, downSuffix string) SqlizeOption {
return newFuncSqlizeOption(func(o *sqlizeOptions) {
o.migrationUpSuffix = upSuffix
o.migrationDownSuffix = downSuffix
})
}
// WithMigrationTable default is 'schema_migration'
func WithMigrationTable(table string) SqlizeOption {
return newFuncSqlizeOption(func(o *sqlizeOptions) {
o.migrationTable = table
})
}
// WithSqlTag default is `sql`
func WithSqlTag(sqlTag string) SqlizeOption {
return newFuncSqlizeOption(func(o *sqlizeOptions) {
o.sqlTag = sqlTag
})
}
// WithMysql default
func WithMysql() SqlizeOption {
return newFuncSqlizeOption(func(o *sqlizeOptions) {
o.dialect = sql_templates.MysqlDialect
})
}
// WithPostgresql ...
func WithPostgresql() SqlizeOption {
return newFuncSqlizeOption(func(o *sqlizeOptions) {
o.dialect = sql_templates.PostgresDialect
})
}
// WithSqlserver ...
func WithSqlserver() SqlizeOption {
return newFuncSqlizeOption(func(o *sqlizeOptions) {
o.dialect = sql_templates.SqlserverDialect
})
}
// WithSqlite ...
func WithSqlite() SqlizeOption {
return newFuncSqlizeOption(func(o *sqlizeOptions) {
o.dialect = sql_templates.SqliteDialect
})
}
// WithSqlUppercase default
func WithSqlUppercase() SqlizeOption {
return newFuncSqlizeOption(func(o *sqlizeOptions) {
o.lowercase = false
})
}
// WithSqlLowercase ...
func WithSqlLowercase() SqlizeOption {
return newFuncSqlizeOption(func(o *sqlizeOptions) {
o.lowercase = true
})
}
// Table name plus s default
func WithPluralTableName() SqlizeOption {
return newFuncSqlizeOption(func(o *sqlizeOptions) {
o.pluralTableName = true
})
}
// WithCommentGenerate default is off
func WithCommentGenerate() SqlizeOption {
return newFuncSqlizeOption(func(o *sqlizeOptions) {
o.generateComment = true
})
}
// WithIgnoreFieldOrder ...
func WithIgnoreFieldOrder() SqlizeOption {
return newFuncSqlizeOption(func(o *sqlizeOptions) {
o.ignoreFieldOrder = true
})
}