@@ -7,6 +7,24 @@ import (
7
7
"time"
8
8
)
9
9
10
+ // Supported dialect
11
+ const (
12
+ SQLITE DialectName = "sqlite" // SQLITE is the SQLite driver name
13
+ SQLITE3 DialectName = "sqlite3" // SQLITE3 is the SQLite driver name
14
+ POSTGRES DialectName = "postgres" // POSTGRES is the PostgreSQL driver name
15
+ MYSQL DialectName = "mysql" // MYSQL is the MySQL driver name
16
+ MSSQL DialectName = "mssql" // MSSQL is the Microsoft SQL Server driver name
17
+ CLICKHOUSE DialectName = "clickhouse" // CLICKHOUSE is the ClickHouse driver name
18
+ CASSANDRA DialectName = "cassandra" // CASSANDRA is the Cassandra driver name
19
+ ELASTICSEARCH DialectName = "elasticsearch" // ELASTICSEARCH is the Elasticsearch driver name
20
+ )
21
+
22
+ // Special conditions for searching
23
+ const (
24
+ SpecialConditionIsNull = "isnull()"
25
+ SpecialConditionIsNotNull = "notnull()"
26
+ )
27
+
10
28
// Connector is an interface for registering database connectors without knowing the specific connector implementations
11
29
type Connector interface {
12
30
ConnectionPool (cfg Config ) (Database , error )
@@ -41,6 +59,9 @@ type Config struct {
41
59
DryRun bool
42
60
UseTruncate bool
43
61
62
+ TLSEnabled bool
63
+ TLSCACert []byte
64
+
44
65
QueryLogger Logger
45
66
ReadedRowsLogger Logger
46
67
QueryTimeLogger Logger
@@ -93,10 +114,38 @@ type databaseQueryRegistrator interface {
93
114
StatementExit (statement string , startTime time.Time , err error , showRowsAffected bool , result Result , format string , args []interface {}, rows Rows , dest []interface {})
94
115
}
95
116
117
+ // Page is a struct for storing pagination information
118
+ type Page struct {
119
+ Limit int64
120
+ Offset int64
121
+ }
122
+
123
+ // SelectCtrl is a struct for storing select control information
124
+ type SelectCtrl struct {
125
+ Fields []string // empty means select count
126
+ Where map [string ][]string
127
+ Order []string
128
+ Page Page
129
+
130
+ OptimizeConditions bool
131
+ }
132
+
96
133
// databaseSearcher is an interface for searching the database
97
134
type databaseSearcher interface {
98
- Search (from string , what string , where string , orderBy string , limit int , explain bool , args ... interface {}) (Rows , error )
99
- Aggregate (from string , what string , where string , groupBy string , orderBy string , limit int , explain bool , args ... interface {}) (Rows , error )
135
+ SearchRaw (from string , what string , where string , orderBy string , limit int , explain bool , args ... interface {}) (Rows , error )
136
+ Search (tableName string , c * SelectCtrl ) (Rows , error )
137
+ }
138
+
139
+ // InsertStats is a struct for storing insert statistics
140
+ type InsertStats struct {
141
+ Successful int64
142
+ Failed int64
143
+ Total int64
144
+ ExpectedSuccesses int64
145
+ }
146
+
147
+ func (s * InsertStats ) String () string {
148
+ return fmt .Sprintf ("successful: %d, failed: %d, total: %d" , s .Successful , s .Failed , s .Total )
100
149
}
101
150
102
151
// databaseInserter is an interface for inserting data into the database
@@ -149,14 +198,22 @@ type Session interface {
149
198
150
199
type TableRow struct {
151
200
Name string
152
- Type string
201
+ Type DataType
153
202
NotNull bool
203
+ Indexed bool // only for Elasticsearch
204
+ }
205
+
206
+ type ResilienceSettings struct {
207
+ NumberOfShards int
208
+ NumberOfReplicas int
154
209
}
155
210
156
211
type TableDefinition struct {
157
212
TableRows []TableRow
158
213
PrimaryKey []string
159
214
Engine string
215
+ Resilience ResilienceSettings
216
+ LMPolicy string // only for Elasticsearch
160
217
}
161
218
162
219
type IndexType string
@@ -235,9 +292,41 @@ type Database interface {
235
292
Close () error
236
293
}
237
294
295
+ type DataType string
296
+
297
+ const (
298
+ DataTypeId DataType = "{$id}"
299
+ DataTypeInt DataType = "{$int}"
300
+ DataTypeString DataType = "{$string}"
301
+ DataTypeString256 DataType = "{$string256}"
302
+ DataTypeBigIntAutoIncPK DataType = "{$bigint_autoinc_pk}"
303
+ DataTypeBigIntAutoInc DataType = "{$bigint_autoinc}"
304
+ DataTypeAscii DataType = "{$ascii}"
305
+ DataTypeUUID DataType = "{$uuid}"
306
+ DataTypeVarCharUUID DataType = "{$varchar_uuid}"
307
+ DataTypeLongBlob DataType = "{$longblob}"
308
+ DataTypeHugeBlob DataType = "{$hugeblob}"
309
+ DataTypeDateTime DataType = "{$datetime}"
310
+ DataTypeDateTime6 DataType = "{$datetime6}"
311
+ DataTypeTimestamp6 DataType = "{$timestamp6}"
312
+ DataTypeCurrentTimeStamp6 DataType = "{$current_timestamp6}"
313
+ DataTypeBinary20 DataType = "{$binary20}"
314
+ DataTypeBinaryBlobType DataType = "{$binaryblobtype}"
315
+ DataTypeBoolean DataType = "{$boolean}"
316
+ DataTypeBooleanFalse DataType = "{$boolean_false}"
317
+ DataTypeBooleanTrue DataType = "{$boolean_true}"
318
+ DataTypeTinyInt DataType = "{$tinyint}"
319
+ DataTypeLongText DataType = "{$longtext}"
320
+ DataTypeUnique DataType = "{$unique}"
321
+ DataTypeEngine DataType = "{$engine}"
322
+ DataTypeNotNull DataType = "{$notnull}"
323
+ DataTypeNull DataType = "{$null}"
324
+ DataTypeTenantUUIDBoundID DataType = "{$tenant_uuid_bound_id}"
325
+ )
326
+
238
327
// Dialect is an interface for database dialects
239
328
type Dialect interface {
240
- GetType (id string ) string
329
+ GetType (id DataType ) string
241
330
}
242
331
243
332
// Recommendation is a struct for storing DB recommendation
@@ -267,6 +356,7 @@ func GetDatabases() []DBType {
267
356
ret = append (ret , DBType {Driver : CLICKHOUSE , Symbol : "C" , Name : "ClickHouse" })
268
357
// "A" is used as the latest symbol of the "Cassandra" due to duplicate with ClickHouse "C"
269
358
ret = append (ret , DBType {Driver : CASSANDRA , Symbol : "A" , Name : "Cassandra" })
359
+ ret = append (ret , DBType {Driver : ELASTICSEARCH , Symbol : "E" , Name : "Elasticsearch" })
270
360
271
361
return ret
272
362
}
0 commit comments