-
Notifications
You must be signed in to change notification settings - Fork 26
/
dialect.go
42 lines (36 loc) · 1.02 KB
/
dialect.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
package qb
// NewDialect returns a dialect pointer given driver
func NewDialect(driver string) Dialect {
dialect, ok := DialectRegistry[driver]
if ok {
return dialect
}
panic("No such dialect: " + driver)
}
// DialectRegistry is a global registry of dialects
var DialectRegistry = make(map[string]Dialect)
// RegisterDialect add a new dialect to the registry
func RegisterDialect(name string, dialect Dialect) {
DialectRegistry[name] = dialect
}
// Dialect is the common interface for driver changes
// It is for fixing compatibility issues of different drivers
type Dialect interface {
GetCompiler() Compiler
CompileType(t TypeElem) string
Escape(str string) string
EscapeAll([]string) []string
SetEscaping(escaping bool)
Escaping() bool
AutoIncrement(column *ColumnElem) string
SupportsUnsigned() bool
Driver() string
WrapError(err error) Error
}
// EscapeAll common escape all
func EscapeAll(dialect Dialect, strings []string) []string {
for k, v := range strings {
strings[k] = dialect.Escape(v)
}
return strings
}