mirror of
https://github.com/geektutu/7days-golang.git
synced 2024-04-21 12:32:11 +00:00
23 lines
574 B
Go
23 lines
574 B
Go
package dialect
|
|
|
|
import "reflect"
|
|
|
|
var dialectsMap = map[string]Dialect{}
|
|
|
|
// Dialect is an interface contains methods that a dialect has to implement
|
|
type Dialect interface {
|
|
DataTypeOf(typ reflect.Value) string
|
|
TableExistSQL(tableName string) (string, []interface{})
|
|
}
|
|
|
|
// RegisterDialect register a dialect to the global variable
|
|
func RegisterDialect(name string, dialect Dialect) {
|
|
dialectsMap[name] = dialect
|
|
}
|
|
|
|
// Get the dialect from global variable if it exists
|
|
func GetDialect(name string) (dialect Dialect, ok bool) {
|
|
dialect, ok = dialectsMap[name]
|
|
return
|
|
}
|