forked from slicebit/qb
/
dialect.go
48 lines (43 loc) · 1.1 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
43
44
45
46
47
48
package qb
// NewDialect returns a dialect pointer given driver
func NewDialect(driver string) Dialect {
switch driver {
case "postgres":
return &PostgresDialect{escaping: false, bindingIndex: 0}
case "mysql":
return &MysqlDialect{false}
case "sqlite3":
return &SqliteDialect{false}
default:
return &DefaultDialect{false}
}
}
// Dialect is the common adapter for driver changes
// It is for fixing compatibility issues of different drivers
type Dialect interface {
Escape(str string) string
EscapeAll([]string) []string
SetEscaping(escaping bool)
Escaping() bool
Placeholder() string
Placeholders(values ...interface{}) []string
AutoIncrement() string
Reset()
SupportsUnsigned() bool
Driver() string
}
// common escape all
func escapeAll(dialect Dialect, strings []string) []string {
for k, v := range strings {
strings[k] = dialect.Escape(v)
}
return strings
}
// common placeholders
func placeholders(dialect Dialect, values ...interface{}) []string {
placeholders := []string{}
for range values {
placeholders = append(placeholders, dialect.Placeholder())
}
return placeholders
}