forked from slicebit/qb
-
Notifications
You must be signed in to change notification settings - Fork 2
/
dialect_default.go
74 lines (60 loc) · 1.87 KB
/
dialect_default.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package qb
import "fmt"
// DefaultDialect is a type of dialect that can be used with unsupported sql drivers
type DefaultDialect struct {
escaping bool
}
// NewDefaultDialect instanciate a DefaultDialect
func NewDefaultDialect() Dialect {
return &DefaultDialect{false}
}
// CompileType compiles a type into its DDL
func (d *DefaultDialect) CompileType(t TypeElem) string {
return DefaultCompileType(t, d.SupportsUnsigned())
}
// Escape wraps the string with escape characters of the dialect
func (d *DefaultDialect) Escape(str string) string {
if d.escaping {
return fmt.Sprintf("`%s`", str)
}
return str
}
// EscapeAll wraps all elements of string array
func (d *DefaultDialect) EscapeAll(strings []string) []string {
return EscapeAll(d, strings[0:])
}
// SetEscaping sets the escaping parameter of dialect
func (d *DefaultDialect) SetEscaping(escaping bool) {
d.escaping = escaping
}
// Escaping gets the escaping parameter of dialect
func (d *DefaultDialect) Escaping() bool {
return d.escaping
}
// AutoIncrement generates auto increment sql of current dialect
func (d *DefaultDialect) AutoIncrement(column *ColumnElem) string {
colSpec := d.CompileType(column.Type)
if column.Options.PrimaryKey {
colSpec += " PRIMARY KEY"
}
colSpec += " AUTO INCREMENT"
return colSpec
}
// SupportsUnsigned returns whether driver supports unsigned type mappings or not
func (d *DefaultDialect) SupportsUnsigned() bool { return false }
// Driver returns the current driver of dialect
func (d *DefaultDialect) Driver() string {
return ""
}
// GetCompiler returns the default SQLCompiler
func (d *DefaultDialect) GetCompiler() Compiler {
return SQLCompiler{d}
}
// WrapError wraps a native error in a qb Error
func (d *DefaultDialect) WrapError(err error) Error {
return Error{Orig: err}
}
func init() {
RegisterDialect("default", NewDefaultDialect())
RegisterDialect("", NewDefaultDialect())
}