This repository has been archived by the owner on Jul 11, 2019. It is now read-only.
forked from go-xorm/xorm
-
Notifications
You must be signed in to change notification settings - Fork 7
/
xorm.go
64 lines (56 loc) · 1.66 KB
/
xorm.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
package xorm
import (
"errors"
"fmt"
"os"
"reflect"
"runtime"
"sync"
)
const (
Version string = "0.3.1"
)
func close(engine *Engine) {
engine.Close()
}
// new a db manager according to the parameter. Currently support four
// drivers
func NewEngine(driverName string, dataSourceName string) (*Engine, error) {
engine := &Engine{DriverName: driverName,
DataSourceName: dataSourceName, Filters: make([]Filter, 0)}
engine.SetMapper(SnakeMapper{})
if driverName == SQLITE {
engine.dialect = &sqlite3{}
} else if driverName == MYSQL {
engine.dialect = &mysql{}
} else if driverName == POSTGRES {
engine.dialect = &postgres{}
engine.Filters = append(engine.Filters, &PgSeqFilter{})
engine.Filters = append(engine.Filters, &QuoteFilter{})
} else if driverName == MYMYSQL {
engine.dialect = &mymysql{}
} else if driverName == "odbc" {
engine.dialect = &mssql{quoteFilter: &QuoteFilter{}}
engine.Filters = append(engine.Filters, &QuoteFilter{})
} else if driverName == ORACLE_OCI {
engine.dialect = &oracle{}
engine.Filters = append(engine.Filters, &QuoteFilter{})
} else {
return nil, errors.New(fmt.Sprintf("Unsupported driver name: %v", driverName))
}
err := engine.dialect.Init(driverName, dataSourceName)
if err != nil {
return nil, err
}
engine.Tables = make(map[reflect.Type]*Table)
engine.mutex = &sync.RWMutex{}
engine.TagIdentifier = "xorm"
engine.Filters = append(engine.Filters, &IdFilter{})
engine.Logger = os.Stdout
//engine.Pool = NewSimpleConnectPool()
//engine.Pool = NewNoneConnectPool()
//engine.Cacher = NewLRUCacher()
err = engine.SetPool(NewSysConnectPool())
runtime.SetFinalizer(engine, close)
return engine, err
}