@@ -7,6 +7,24 @@ import (
77 "time"
88)
99
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+
1028// Connector is an interface for registering database connectors without knowing the specific connector implementations
1129type Connector interface {
1230 ConnectionPool (cfg Config ) (Database , error )
@@ -41,6 +59,9 @@ type Config struct {
4159 DryRun bool
4260 UseTruncate bool
4361
62+ TLSEnabled bool
63+ TLSCACert []byte
64+
4465 QueryLogger Logger
4566 ReadedRowsLogger Logger
4667 QueryTimeLogger Logger
@@ -93,10 +114,38 @@ type databaseQueryRegistrator interface {
93114 StatementExit (statement string , startTime time.Time , err error , showRowsAffected bool , result Result , format string , args []interface {}, rows Rows , dest []interface {})
94115}
95116
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+
96133// databaseSearcher is an interface for searching the database
97134type 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 )
100149}
101150
102151// databaseInserter is an interface for inserting data into the database
@@ -149,14 +198,22 @@ type Session interface {
149198
150199type TableRow struct {
151200 Name string
152- Type string
201+ Type DataType
153202 NotNull bool
203+ Indexed bool // only for Elasticsearch
204+ }
205+
206+ type ResilienceSettings struct {
207+ NumberOfShards int
208+ NumberOfReplicas int
154209}
155210
156211type TableDefinition struct {
157212 TableRows []TableRow
158213 PrimaryKey []string
159214 Engine string
215+ Resilience ResilienceSettings
216+ LMPolicy string // only for Elasticsearch
160217}
161218
162219type IndexType string
@@ -235,9 +292,41 @@ type Database interface {
235292 Close () error
236293}
237294
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+
238327// Dialect is an interface for database dialects
239328type Dialect interface {
240- GetType (id string ) string
329+ GetType (id DataType ) string
241330}
242331
243332// Recommendation is a struct for storing DB recommendation
@@ -267,6 +356,7 @@ func GetDatabases() []DBType {
267356 ret = append (ret , DBType {Driver : CLICKHOUSE , Symbol : "C" , Name : "ClickHouse" })
268357 // "A" is used as the latest symbol of the "Cassandra" due to duplicate with ClickHouse "C"
269358 ret = append (ret , DBType {Driver : CASSANDRA , Symbol : "A" , Name : "Cassandra" })
359+ ret = append (ret , DBType {Driver : ELASTICSEARCH , Symbol : "E" , Name : "Elasticsearch" })
270360
271361 return ret
272362}
0 commit comments