forked from gobuffalo/pop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pop.go
65 lines (51 loc) · 1.9 KB
/
pop.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
package pop
import "strings"
// EagerMode type for all eager modes supported in pop.
type EagerMode uint8
const (
eagerModeNil EagerMode = iota
// EagerDefault is the current implementation, the default
// behavior of pop. This one introduce N+1 problem and will be used as
// default value for backward compatibility.
EagerDefault
// EagerPreload mode works similar to Preload mode used in Rails ActiveRecord.
// Avoid N+1 problem by reducing the number of hits to the database but
// increase memory use to process and link associations to parent.
EagerPreload
// EagerInclude This mode works similar to Include mode used in rails ActiveRecord.
// Use Left Join clauses to load associations. Not working yet.
EagerInclude
)
// default loading Association Strategy definition.
var loadingAssociationsStrategy = EagerDefault
// SetEagerMode changes overall mode when eager loading.
// this will change the default loading associations strategy for all Eager queries.
// This will affect all queries when eager loading is used.
func SetEagerMode(eagerMode EagerMode) {
loadingAssociationsStrategy = eagerMode
}
// AvailableDialects lists the available database dialects
var AvailableDialects []string
var dialectSynonyms = make(map[string]string)
// map of dialect specific url parsers
var urlParser = make(map[string]func(*ConnectionDetails) error)
// map of dialect specific connection details finalizers
var finalizer = make(map[string]func(*ConnectionDetails))
// map of connection creators
var newConnection = make(map[string]func(*ConnectionDetails) (dialect, error))
// DialectSupported checks support for the given database dialect
func DialectSupported(d string) bool {
for _, ad := range AvailableDialects {
if ad == d {
return true
}
}
return false
}
func normalizeSynonyms(dialect string) string {
d := strings.ToLower(dialect)
if syn, ok := dialectSynonyms[d]; ok {
d = syn
}
return d
}