-
Notifications
You must be signed in to change notification settings - Fork 0
/
xq.go
63 lines (53 loc) · 1.76 KB
/
xq.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
package xq
import (
"github.com/go-xe2/x/core/exception"
"github.com/go-xe2/x/xf/ef/xq/xdatabase"
"github.com/go-xe2/x/xf/ef/xq/xdelete"
"github.com/go-xe2/x/xf/ef/xq/xinsert"
xquery2 "github.com/go-xe2/x/xf/ef/xq/xquery"
"github.com/go-xe2/x/xf/ef/xq/xupdate"
"github.com/go-xe2/x/xf/ef/xqi"
)
// 通过名称获取指定数据库
// @param dbName 配置的数据库名称
func Database(dbName ...string) xqi.Database {
return xdatabase.DB(dbName...)
}
// 在指定数据库上查询数据
// @param dbName 为空时在默认数据库上查询数据
func Query(dbName ...string) xqi.QuerySelect {
db := Database(dbName...)
if db == nil {
panic(exception.NewText("未设置默认数据库"))
}
return xquery2.NewQueryExp(db)
}
// 在指定数据库上查询数据
func QueryByDb(db xqi.Database) xqi.QuerySelect {
return xquery2.NewQueryExp(db)
}
// 在指定名称的数据库上向指定表插入数据
func Insert(table xqi.SqlTable, dbName ...string) xinsert.SqlInsert {
db := Database(dbName...)
return xinsert.Insert(db, table)
}
// 在指定的数据库上向指定表插入数据
func InsertByDb(table xqi.SqlTable, db xqi.Database) xinsert.SqlInsert {
return xinsert.Insert(db, table)
}
// 在指定名称的数据库上更新数据库表
func Update(table xqi.SqlTable, dbName ...string) xupdate.SqlUpdate {
db := Database(dbName...)
return xupdate.Update(db, table)
}
// 在指定的数据库上更新数据库表
func UpdateByDb(table xqi.SqlTable, db xqi.Database) xupdate.SqlUpdate {
return xupdate.Update(db, table)
}
func Delete(table xqi.SqlTable, dbName ...string) xdelete.SqlDelete {
db := Database(dbName...)
return xdelete.Delete(table, db)
}
func DeleteByDb(table xqi.SqlTable, db xqi.Database) xdelete.SqlDelete {
return xdelete.Delete(table, db)
}