-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsqlang.go
195 lines (158 loc) · 3.84 KB
/
sqlang.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
package sqlite
///////////////////////////////////////////////////////////////////////////////
// INTERFACES
// SQStatement is any statement which can be prepared or executed
type SQStatement interface {
SQExpr
Query() string
}
// SQSource defines a table or column name
type SQSource interface {
SQExpr
// Return name, schema, type
Name() string
Schema() string
Alias() string
// Modify the source
WithName(string) SQSource
WithSchema(string) SQSource
WithType(string) SQColumn
WithAlias(string) SQSource
WithDesc() SQSource
// Insert, replace or upsert a row with named columns
Insert(...string) SQInsert
Replace(...string) SQInsert
// Drop objects
DropTable() SQDrop
DropIndex() SQDrop
DropTrigger() SQDrop
DropView() SQDrop
// Create objects
CreateTable(...SQColumn) SQTable
CreateVirtualTable(string, ...string) SQIndexView
CreateIndex(string, ...string) SQIndexView
CreateTrigger(string, ...SQStatement) SQTrigger
CreateView(SQSelect, ...string) SQIndexView
ForeignKey(...string) SQForeignKey
// Alter objects
AlterTable() SQAlter
// Update and delete data
Update(...string) SQUpdate
Delete(...interface{}) SQStatement
}
// SQJoin defines one or more joins
type SQJoin interface {
SQExpr
Join(...SQExpr) SQJoin
LeftJoin(...SQExpr) SQJoin
LeftInnerJoin(...SQExpr) SQJoin
Using(...string) SQJoin
}
// SQTable defines a table of columns and indexes
type SQTable interface {
SQStatement
IfNotExists() SQTable
WithTemporary() SQTable
WithoutRowID() SQTable
WithIndex(...string) SQTable
WithUnique(...string) SQTable
WithForeignKey(SQForeignKey, ...string) SQTable
}
// SQUpdate defines an update statement
type SQUpdate interface {
SQStatement
// Modifiers
WithAbort() SQUpdate
WithFail() SQUpdate
WithIgnore() SQUpdate
WithReplace() SQUpdate
WithRollback() SQUpdate
// Where clause
Where(...interface{}) SQUpdate
}
// SQIndexView defines a create index or view statement
type SQIndexView interface {
SQStatement
SQSource
// Return properties
Unique() bool
Table() string
Columns() []string
Auto() bool
// Modifiers
IfNotExists() SQIndexView
WithTemporary() SQIndexView
WithUnique() SQIndexView
WithAuto() SQIndexView
Options(...string) SQIndexView
}
// SQTrigger defines a create trigger statement
type SQTrigger interface {
SQStatement
// Modifiers
IfNotExists() SQTrigger
WithTemporary() SQTrigger
Before() SQTrigger
After() SQTrigger
InsteadOf() SQTrigger
Delete() SQTrigger
Insert() SQTrigger
Update(...string) SQTrigger
}
// SQDrop defines a drop for tables, views, indexes, and triggers
type SQDrop interface {
SQStatement
IfExists() SQDrop
}
// SQInsert defines an insert or replace statement
type SQInsert interface {
SQStatement
DefaultValues() SQInsert
WithConflictDoNothing(...string) SQInsert
WithConflictUpdate(...string) SQInsert
}
// SQSelect defines a select statement
type SQSelect interface {
SQStatement
// Set select flags
WithDistinct() SQSelect
WithLimitOffset(limit, offset uint) SQSelect
// Destination expressions for results
To(...SQExpr) SQSelect
// Where and order clauses
Where(...interface{}) SQSelect
Order(...SQSource) SQSelect
}
// SQAlter defines an alter table statement
type SQAlter interface {
SQStatement
// Alter operation
AddColumn(SQColumn) SQStatement
DropColumn(SQColumn) SQStatement
}
// SQForeignKey represents a foreign key constraint
type SQForeignKey interface {
// Modifiers
OnDeleteCascade() SQForeignKey
}
// SQColumn represents a column definition
type SQColumn interface {
SQExpr
// Properties
Name() string
Type() string
Nullable() bool
Primary() string
// Modifiers
NotNull() SQColumn
WithType(string) SQColumn
WithAlias(string) SQSource
WithPrimary() SQColumn
WithAutoIncrement() SQColumn
WithDefault(v interface{}) SQColumn
WithDefaultNow() SQColumn
}
// SQExpr defines any expression
type SQExpr interface {
String() string
}