forked from slicebit/qb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dialect_postgres.go
59 lines (47 loc) · 1.58 KB
/
dialect_postgres.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
package qb
import "fmt"
// PostgresDialect is a type of dialect that can be used with postgres driver
type PostgresDialect struct {
bindingIndex int
escaping bool
}
// Escape wraps the string with escape characters of the dialect
func (d *PostgresDialect) Escape(str string) string {
if d.escaping {
return fmt.Sprintf("\"%s\"", str)
}
return str
}
// EscapeAll wraps all elements of string array
func (d *PostgresDialect) EscapeAll(strings []string) []string {
return escapeAll(d, strings[0:])
}
// SetEscaping sets the escaping parameter of dialect
func (d *PostgresDialect) SetEscaping(escaping bool) {
d.escaping = escaping
}
// Escaping gets the escaping parameter of dialect
func (d *PostgresDialect) Escaping() bool {
return d.escaping
}
// Placeholder returns the placeholder for bindings in the sql
func (d *PostgresDialect) Placeholder() string {
d.bindingIndex++
return fmt.Sprintf("$%d", d.bindingIndex)
}
// Placeholders returns the placeholders for bindings in the sql
func (d *PostgresDialect) Placeholders(values ...interface{}) []string {
return placeholders(d, values...)
}
// AutoIncrement generates auto increment sql of current dialect
func (d *PostgresDialect) AutoIncrement() string {
return ""
}
// Reset clears the binding index for postgres driver
func (d *PostgresDialect) Reset() { d.bindingIndex = 0 }
// SupportsUnsigned returns whether driver supports unsigned type mappings or not
func (d *PostgresDialect) SupportsUnsigned() bool { return false }
// Driver returns the current driver of dialect
func (d *PostgresDialect) Driver() string {
return "postgres"
}