github.com/nshntarora/pop@v0.1.2/pop.go (about) 1 package pop 2 3 import "strings" 4 5 // EagerMode type for all eager modes supported in pop. 6 type EagerMode uint8 7 8 const ( 9 eagerModeNil EagerMode = iota 10 // EagerDefault is the current implementation, the default 11 // behavior of pop. This one introduce N+1 problem and will be used as 12 // default value for backward compatibility. 13 EagerDefault 14 15 // EagerPreload mode works similar to Preload mode used in Rails ActiveRecord. 16 // Avoid N+1 problem by reducing the number of hits to the database but 17 // increase memory use to process and link associations to parent. 18 EagerPreload 19 20 // EagerInclude This mode works similar to Include mode used in rails ActiveRecord. 21 // Use Left Join clauses to load associations. Not working yet. 22 EagerInclude 23 ) 24 25 // default loading Association Strategy definition. 26 var loadingAssociationsStrategy = EagerDefault 27 28 // SetEagerMode changes overall mode when eager loading. 29 // this will change the default loading associations strategy for all Eager queries. 30 // This will affect all queries when eager loading is used. 31 func SetEagerMode(eagerMode EagerMode) { 32 loadingAssociationsStrategy = eagerMode 33 } 34 35 // AvailableDialects lists the available database dialects 36 var AvailableDialects []string 37 38 var dialectSynonyms = make(map[string]string) 39 40 // map of dialect specific url parsers 41 var urlParser = make(map[string]func(*ConnectionDetails) error) 42 43 // map of dialect specific connection details finalizers 44 var finalizer = make(map[string]func(*ConnectionDetails)) 45 46 // map of connection creators 47 var newConnection = make(map[string]func(*ConnectionDetails) (dialect, error)) 48 49 // DialectSupported checks support for the given database dialect 50 func DialectSupported(d string) bool { 51 for _, ad := range AvailableDialects { 52 if ad == d { 53 return true 54 } 55 } 56 return false 57 } 58 59 // CanonicalDialect checks if the given synonym (could be a valid dialect too) 60 // is a registered synonym and returns the canonical dialect for the synonym. 61 // Otherwise, it returns the lowercase value of the given synonym. 62 // 63 // Note that it does not check if the return value is a valid (supported) 64 // dialect so you need to check it with `DialectSupported()`. 65 func CanonicalDialect(synonym string) string { 66 d := strings.ToLower(synonym) 67 if syn, ok := dialectSynonyms[d]; ok { 68 d = syn 69 } 70 return d 71 }