add querya

This commit is contained in:
Star 2025-01-14 14:28:26 +08:00
parent 7eee72b053
commit 12fcb95b9d
3 changed files with 31 additions and 10 deletions

14
db.go
View File

@ -70,6 +70,20 @@ func makeDBObject(conn *db.DB, tx *db.Tx) map[string]any {
panic(vm.NewGoError(r.Error))
}
},
"querya": func(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value {
args, conn, tx, _ := initDBArgs(argsIn, vm, 1)
var r *db.QueryResult
if tx != nil {
r = tx.Query(args.Str(0), args.Array(1)...)
} else {
r = conn.Query(args.Str(0), args.Array(1)...)
}
if r.Error == nil {
return vm.ToValue(makeQueryResult(r, r.SliceResults()))
} else {
panic(vm.NewGoError(r.Error))
}
},
"query1": func(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value {
args, conn, tx, _ := initDBArgs(argsIn, vm, 1)
var r *db.QueryResult

10
db.ts
View File

@ -7,6 +7,7 @@ export default {
makeER,
query,
query1,
query1a,
query11,
exec,
insert,
@ -23,7 +24,9 @@ function setDefault(dbName: string): void { }
function make(descFileOrContent: string): Object[] { return null as any }
function makeER(outputFile: string, descFileOrContent: string): void { }
function query(sql: string, ...args: any): QueryResult { return null as any }
function querya(sql: string, ...args: any): QueryResultA { return null as any }
function query1(sql: string, ...args: any): QueryResult1 { return null as any }
function query1a(sql: string, ...args: any): QueryResult1A { return null as any }
function query11(sql: string, ...args: any): QueryResult11 { return null as any }
function exec(sql: string, ...args: any): ExecResult { return null as any }
function insert(table: string, data: Object): ExecResult { return null as any }
@ -38,6 +41,7 @@ interface DB {
make(descFileOrContent: string): Object[]
query(sql: string, ...args: any): QueryResult
query1(sql: string, ...args: any): QueryResult1
query1a(sql: string, ...args: any): QueryResult1A
query11(sql: string, ...args: any): QueryResult11
exec(sql: string, ...args: any): ExecResult
insert(table: string, data: Object): ExecResult
@ -69,6 +73,12 @@ interface QueryResult {
result: Object[]
}
interface QueryResultA {
sql: string
args: any[]
result: any[][]
}
interface QueryResult1 {
sql: string
args: any[]

17
go.mod
View File

@ -1,16 +1,14 @@
module apigo.cc/gojs/db
go 1.22.0
toolchain go1.22.5
go 1.21
require (
apigo.cc/gojs v0.0.9
github.com/ssgo/dao v0.1.5
apigo.cc/gojs v0.0.12
github.com/ssgo/dao v0.1.7
github.com/ssgo/db v1.7.11
github.com/ssgo/log v1.7.7
github.com/ssgo/u v1.7.13
modernc.org/sqlite v1.34.2
modernc.org/sqlite v1.34.4
)
require (
@ -29,13 +27,12 @@ require (
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/ssgo/config v1.7.9 // indirect
github.com/ssgo/standard v1.7.7 // indirect
github.com/ssgo/tool v0.4.27 // indirect
golang.org/x/exp v0.0.0-20241210194714-1829a127f884 // indirect
github.com/ssgo/tool v0.4.28 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
modernc.org/gc/v3 v3.0.0-20241213165251-3bc300f6d0c9 // indirect
modernc.org/libc v1.61.4 // indirect
modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6 // indirect
modernc.org/libc v1.55.3 // indirect
modernc.org/mathutil v1.6.0 // indirect
modernc.org/memory v1.8.0 // indirect
modernc.org/strutil v1.2.0 // indirect