fix nil bug for query11
add query1s query1a
This commit is contained in:
parent
183beb1286
commit
7eee72b053
24
db.go
24
db.go
@ -84,6 +84,28 @@ func makeDBObject(conn *db.DB, tx *db.Tx) map[string]any {
|
||||
panic(vm.NewGoError(r.Error))
|
||||
}
|
||||
},
|
||||
"query1a": 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 {
|
||||
a := r.SliceResults()
|
||||
if len(a) > 0 && len(a[0]) > 0 {
|
||||
list := make([]any, len(a))
|
||||
for i := 0; i < len(a); i++ {
|
||||
list[i] = a[i][0]
|
||||
}
|
||||
return vm.ToValue(makeQueryResult(r, list))
|
||||
}
|
||||
return vm.ToValue(makeQueryResult(r, nil))
|
||||
} else {
|
||||
panic(vm.NewGoError(r.Error))
|
||||
}
|
||||
},
|
||||
"query11": func(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value {
|
||||
args, conn, tx, _ := initDBArgs(argsIn, vm, 1)
|
||||
var r *db.QueryResult
|
||||
@ -97,7 +119,7 @@ func makeDBObject(conn *db.DB, tx *db.Tx) map[string]any {
|
||||
if len(a) > 0 && len(a[0]) > 0 {
|
||||
return vm.ToValue(makeQueryResult(r, a[0][0]))
|
||||
}
|
||||
return vm.ToValue(nil)
|
||||
return vm.ToValue(makeQueryResult(r, nil))
|
||||
} else {
|
||||
panic(vm.NewGoError(r.Error))
|
||||
}
|
||||
|
21
db.ts
21
db.ts
@ -20,7 +20,7 @@ export default {
|
||||
|
||||
function get(dbName: string): DB { return null as any }
|
||||
function setDefault(dbName: string): void { }
|
||||
function make(descFileOrContent: string): Array<Object> { return null as any }
|
||||
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 query1(sql: string, ...args: any): QueryResult1 { return null as any }
|
||||
@ -35,7 +35,7 @@ function begin(): Tx { return null as any }
|
||||
function makeInKeys(numKeys: number): string { return '' }
|
||||
|
||||
interface DB {
|
||||
make(descFileOrContent: string): Array<Object>
|
||||
make(descFileOrContent: string): Object[]
|
||||
query(sql: string, ...args: any): QueryResult
|
||||
query1(sql: string, ...args: any): QueryResult1
|
||||
query11(sql: string, ...args: any): QueryResult11
|
||||
@ -52,6 +52,7 @@ interface DB {
|
||||
interface Tx {
|
||||
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
|
||||
@ -64,25 +65,31 @@ interface Tx {
|
||||
|
||||
interface QueryResult {
|
||||
sql: string
|
||||
args: Array<any>
|
||||
result: Array<Object>
|
||||
args: any[]
|
||||
result: Object[]
|
||||
}
|
||||
|
||||
interface QueryResult1 {
|
||||
sql: string
|
||||
args: Array<any>
|
||||
args: any[]
|
||||
result: Object
|
||||
}
|
||||
|
||||
interface QueryResult1A {
|
||||
sql: string
|
||||
args: any[]
|
||||
result: any[]
|
||||
}
|
||||
|
||||
interface QueryResult11 {
|
||||
sql: string
|
||||
args: Array<any>
|
||||
args: any[]
|
||||
result: any
|
||||
}
|
||||
|
||||
interface ExecResult {
|
||||
sql: string
|
||||
args: Array<any>
|
||||
args: any[]
|
||||
id: number
|
||||
changes: number
|
||||
}
|
||||
|
8
go.mod
8
go.mod
@ -1,11 +1,11 @@
|
||||
module apigo.cc/gojs/db
|
||||
|
||||
go 1.21
|
||||
go 1.22.0
|
||||
|
||||
toolchain go1.22.5
|
||||
|
||||
require (
|
||||
apigo.cc/gojs v0.0.8
|
||||
apigo.cc/gojs v0.0.9
|
||||
github.com/ssgo/dao v0.1.5
|
||||
github.com/ssgo/db v1.7.11
|
||||
github.com/ssgo/log v1.7.7
|
||||
@ -30,11 +30,11 @@ require (
|
||||
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-20231108232855-2478ac86f678 // indirect
|
||||
golang.org/x/exp v0.0.0-20241210194714-1829a127f884 // 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-20241004144649-1aea3fae8852 // indirect
|
||||
modernc.org/gc/v3 v3.0.0-20241213165251-3bc300f6d0c9 // indirect
|
||||
modernc.org/libc v1.61.4 // indirect
|
||||
modernc.org/mathutil v1.6.0 // indirect
|
||||
modernc.org/memory v1.8.0 // indirect
|
||||
|
Loading…
Reference in New Issue
Block a user