forked from Oskang09/goloquent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdialect.go
52 lines (47 loc) · 1.36 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
49
50
51
52
package goloquent
import (
"context"
"database/sql"
"encoding/json"
"reflect"
)
// Dialect :
type Dialect interface {
Open(c Config) (*sql.DB, error)
SetDB(db Client)
GetTable(ns string) string
Version(ctx context.Context) (ver string)
CurrentDB(ctx context.Context) (n string)
Quote(n string) string
Bind(i uint) string
FilterJSON(f Filter) (s string, args []interface{}, err error)
JSONMarshal(i interface{}) (b json.RawMessage)
Value(v interface{}) string
GetSchema(c Column) []Schema
DataType(s Schema) string
HasTable(ctx context.Context, tb string) bool
HasIndex(ctx context.Context, tb, idx string) bool
GetColumns(ctx context.Context, tb string) (cols []string)
GetIndexes(ctx context.Context, tb string) (idxs []string)
CreateTable(ctx context.Context, tb string, cols []Column) error
AlterTable(ctx context.Context, tb string, cols []Column, unsafe bool) error
OnConflictUpdate(tb string, cols []string) string
UpdateWithLimit() bool
ReplaceInto(ctx context.Context, src, dst string) error
}
var (
dialects = make(map[string]Dialect)
)
// RegisterDialect :
func RegisterDialect(driver string, d Dialect) {
dialects[driver] = d
}
// GetDialect :
func GetDialect(driver string) (d Dialect, isValid bool) {
d, isValid = dialects[driver]
if isValid {
// Clone a new dialect
d = reflect.New(reflect.TypeOf(d).Elem()).Interface().(Dialect)
}
return
}