chore: infrastructure alignment and doc sync (by checkall)
This commit is contained in:
parent
ae534db085
commit
12651fb142
63
DB.go
63
DB.go
@ -349,6 +349,69 @@ func GetDB(name string, logger *log.Logger) *DB {
|
||||
return getDB(name, logger, true)
|
||||
}
|
||||
|
||||
// Sync 同步数据库结构 (使用默认实例 "default")
|
||||
func Sync(desc string) error {
|
||||
d := GetDB("default", nil)
|
||||
if d == nil {
|
||||
return errors.New("default db not configured")
|
||||
}
|
||||
return d.Sync(desc)
|
||||
}
|
||||
|
||||
// Insert 插入数据 (使用默认实例 "default")
|
||||
func Insert(table string, data any) *ExecResult {
|
||||
d := GetDB("default", nil)
|
||||
if d == nil {
|
||||
return &ExecResult{Error: errors.New("default db not configured")}
|
||||
}
|
||||
return d.Insert(table, data)
|
||||
}
|
||||
|
||||
// Update 更新数据 (使用默认实例 "default")
|
||||
func Update(table string, data any, conditions string, args ...any) *ExecResult {
|
||||
d := GetDB("default", nil)
|
||||
if d == nil {
|
||||
return &ExecResult{Error: errors.New("default db not configured")}
|
||||
}
|
||||
return d.Update(table, data, conditions, args...)
|
||||
}
|
||||
|
||||
// Delete 删除数据 (使用默认实例 "default")
|
||||
func Delete(table string, conditions string, args ...any) *ExecResult {
|
||||
d := GetDB("default", nil)
|
||||
if d == nil {
|
||||
return &ExecResult{Error: errors.New("default db not configured")}
|
||||
}
|
||||
return d.Delete(table, conditions, args...)
|
||||
}
|
||||
|
||||
// Query 查询数据 (使用默认实例 "default")
|
||||
func Query(query string, args ...any) *QueryResult {
|
||||
d := GetDB("default", nil)
|
||||
if d == nil {
|
||||
return &QueryResult{Error: errors.New("default db not configured")}
|
||||
}
|
||||
return d.Query(query, args...)
|
||||
}
|
||||
|
||||
// Exec 执行 SQL (使用默认实例 "default")
|
||||
func Exec(query string, args ...any) *ExecResult {
|
||||
d := GetDB("default", nil)
|
||||
if d == nil {
|
||||
return &ExecResult{Error: errors.New("default db not configured")}
|
||||
}
|
||||
return d.Exec(query, args...)
|
||||
}
|
||||
|
||||
// Begin 开始事务 (使用默认实例 "default")
|
||||
func Begin() *Tx {
|
||||
d := GetDB("default", nil)
|
||||
if d == nil {
|
||||
return &Tx{Error: errors.New("default db not configured")}
|
||||
}
|
||||
return d.Begin()
|
||||
}
|
||||
|
||||
func getDB(name string, logger *log.Logger, useCache bool) *DB {
|
||||
if logger == nil {
|
||||
logger = log.DefaultLogger
|
||||
|
||||
4
go.mod
4
go.mod
@ -3,9 +3,10 @@ module apigo.cc/go/db
|
||||
go 1.25.0
|
||||
|
||||
require (
|
||||
apigo.cc/go/cast v1.3.0
|
||||
apigo.cc/go/cast v1.3.2
|
||||
apigo.cc/go/config v1.3.0
|
||||
apigo.cc/go/crypto v1.3.0
|
||||
apigo.cc/go/file v1.3.1
|
||||
apigo.cc/go/id v1.3.0
|
||||
apigo.cc/go/log v1.3.2
|
||||
apigo.cc/go/rand v1.3.0
|
||||
@ -20,7 +21,6 @@ require (
|
||||
|
||||
require (
|
||||
apigo.cc/go/encoding v1.3.0 // indirect
|
||||
apigo.cc/go/file v1.3.0 // indirect
|
||||
filippo.io/edwards25519 v1.2.0 // indirect
|
||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||
github.com/gomodule/redigo v2.0.0+incompatible // indirect
|
||||
|
||||
8
go.sum
8
go.sum
@ -1,13 +1,13 @@
|
||||
apigo.cc/go/cast v1.3.0 h1:ZTcLYijkqZjSWSCSpJUWMfzJYeJKbwKxquKkPrFsROQ=
|
||||
apigo.cc/go/cast v1.3.0/go.mod h1:lGlwImiOvHxG7buyMWhFzcdvQzmSaoKbmr7bcDfUpHk=
|
||||
apigo.cc/go/cast v1.3.2 h1:hh9MWDSwh3T/kQdCHjFpjDwHrh2A05Q4wt1AAWs8NBI=
|
||||
apigo.cc/go/cast v1.3.2/go.mod h1:lGlwImiOvHxG7buyMWhFzcdvQzmSaoKbmr7bcDfUpHk=
|
||||
apigo.cc/go/config v1.3.0 h1:TwI3bv3D+BJrAnFx+o62HQo3FarY2Ge3SCGsKchFYGg=
|
||||
apigo.cc/go/config v1.3.0/go.mod h1:88lqKEBXlIExFKt1geLONVLYyM+QhRVpBe0ok3OEvjI=
|
||||
apigo.cc/go/crypto v1.3.0 h1:rGRrrb5O+4M50X5hVUmJQbXx3l87zzlcgzGtUvZrZL8=
|
||||
apigo.cc/go/crypto v1.3.0/go.mod h1:uSCcmbcFoiltUPMQTSuqmU9nfKEH/lRs7nQ7aa3Z4Mc=
|
||||
apigo.cc/go/encoding v1.3.0 h1:8jqNHoZBR8vOU/BGsLFebfp1Txa1UxDRpd7YwzIFLJs=
|
||||
apigo.cc/go/encoding v1.3.0/go.mod h1:kT/uUJiuAOkZ4LzUWrUtk/I0iL1D8aatvD+59bDnHBo=
|
||||
apigo.cc/go/file v1.3.0 h1:xG9FcY3Rv6Br83r9pq9QsIXFrplx4g8ITOkHSzfzXRg=
|
||||
apigo.cc/go/file v1.3.0/go.mod h1:pYHBlB/XwsrnWpEh7GIFpbiqobrExfiB+rEN8V2d2kY=
|
||||
apigo.cc/go/file v1.3.1 h1:qHgiJsn1K9DazWRrPoHVnXtp6hDGGsUpAE/4G1bFXqY=
|
||||
apigo.cc/go/file v1.3.1/go.mod h1:pYHBlB/XwsrnWpEh7GIFpbiqobrExfiB+rEN8V2d2kY=
|
||||
apigo.cc/go/id v1.3.0 h1:Tr2Yj0Rl19lfwW5wBTJ407o/zgo2oVRLE20WWEgJzdE=
|
||||
apigo.cc/go/id v1.3.0/go.mod h1:AFH3kMFwENfXNyijnAFWEhSF1o3y++UBPem1IUlrcxA=
|
||||
apigo.cc/go/log v1.3.2 h1:/m3V4MnlYnCG4XPHpWDsa4cw5suMaDVY1SgaVyjnBSo=
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user