-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
55 lines (47 loc) · 1.21 KB
/
main.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
// orm/mainServer.go
// 负责数据库读取
package orm
import (
err "../../cc/err"
err_code "../../cc/err_code"
"github.com/kpango/glg"
_ "github.com/mattn/go-sqlite3"
"xorm.io/xorm"
)
var (
engine_account *xorm.Engine
engine_post *xorm.Engine
engine_chat *xorm.Engine
engine_dm *xorm.Engine
engine_vp *xorm.Engine
)
// 初始化sqlite数据库orm
// 有可能panic创建数据库引擎的错误
func connectDb( ppEnginePost **xorm.Engine, dbName, dbPath string ) {
var e error
*ppEnginePost, e = xorm.NewEngine("sqlite3", dbPath + dbName )
err.Assert( e )
glg.Success("orm to " + dbName + " (sqlite3)")
}
func InitEngine( dbPath string ) {
glg.Log("orm loading...")
defer func() {
if r := recover(); r != nil {
_ = glg.Error(r)
err.Exit( err_code.ERR_INIT_ORM )
}
}()
connectDb( &engine_account, "account.db", dbPath )
Sync2Account()
connectDb( &engine_post, "post.db", dbPath )
Sync2Post()
connectDb( &engine_chat, "chat.db", dbPath )
Sync2Chat()
connectDb( &engine_dm, "dm_1.db", dbPath )
Sync2DM1()
connectDb( &engine_vp, "vp.db", dbPath )
Sync2VP()
// e = NewAccount("cyf","cyf-ms@hotmail.com","18217203406","19990908cyfcyfcyfcyf")
// err.Assert( e )
glg.Log("orm finished loading...")
}