add SetSSKey

add makeInKeys
This commit is contained in:
Star 2024-10-27 00:36:18 +08:00
parent a527592867
commit 9cd64d91d0
2 changed files with 41 additions and 30 deletions

7
db.go
View File

@ -46,6 +46,9 @@ func init() {
Desc: "db api by github.com/ssgo/db", Desc: "db api by github.com/ssgo/db",
TsCode: dbTS, TsCode: dbTS,
Example: dbMD, Example: dbMD,
SetSSKey: func(key, iv []byte) {
db.SetEncryptKeys(key, iv)
},
}) })
} }
@ -169,6 +172,10 @@ func makeDBObject(conn *db.DB, tx *db.Tx) map[string]any {
panic(vm.NewGoError(r.Error)) panic(vm.NewGoError(r.Error))
} }
}, },
"makeInKeys": func(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value {
args := gojs.MakeArgs(&argsIn, vm).Check(1)
return vm.ToValue(db.InKeys(args.Int(0)))
},
} }
if tx == nil { if tx == nil {

64
db.ts
View File

@ -14,46 +14,50 @@ export default {
delete: delete_, delete: delete_,
destroy, destroy,
begin, begin,
makeInKeys,
} }
function get(dbName: string): DB {return null as any} function get(dbName: string): DB { return null as any }
function setDefault(dbName: string): void {} function setDefault(dbName: string): void { }
function make(descFileOrContent: string): Array<Object>{return null as any} function make(descFileOrContent: string): Array<Object> { return null as any }
function query(sql: string, ...args:any): QueryResult{return null as any} function query(sql: string, ...args: any): QueryResult { return null as any }
function query1(sql: string, ...args:any): QueryResult1{return null as any} function query1(sql: string, ...args: any): QueryResult1 { return null as any }
function query11(sql: string, ...args:any): QueryResult11{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 exec(sql: string, ...args: any): ExecResult { return null as any }
function insert(table: string, data:Object): ExecResult{return null as any} function insert(table: string, data: Object): ExecResult { return null as any }
function replace(table: string, data:Object): ExecResult{return null as any} function replace(table: string, data: Object): ExecResult { return null as any }
function update(table: string, data:Object, where: string, ...args:any): ExecResult{return null as any} function update(table: string, data: Object, where: string, ...args: any): ExecResult { return null as any }
function delete_(table: string, where: string, ...args:any): ExecResult{return null as any} function delete_(table: string, where: string, ...args: any): ExecResult { return null as any }
function destroy(): void{} function destroy(): void { }
function begin(): Tx{return null as any} function begin(): Tx { return null as any }
function makeInKeys(numKeys: number): string { return '' }
interface DB { interface DB {
make(descFileOrContent: string): Array<Object> make(descFileOrContent: string): Array<Object>
query(sql: string, ...args:any): QueryResult query(sql: string, ...args: any): QueryResult
query1(sql: string, ...args:any): QueryResult1 query1(sql: string, ...args: any): QueryResult1
query11(sql: string, ...args:any): QueryResult11 query11(sql: string, ...args: any): QueryResult11
exec(sql: string, ...args:any): ExecResult exec(sql: string, ...args: any): ExecResult
insert(table: string, data:Object): ExecResult insert(table: string, data: Object): ExecResult
replace(table: string, data:Object): ExecResult replace(table: string, data: Object): ExecResult
update(table: string, data:Object, where: string, ...args:any): ExecResult update(table: string, data: Object, where: string, ...args: any): ExecResult
delete(table: string, where: string, ...args:any): ExecResult delete(table: string, where: string, ...args: any): ExecResult
destroy(): void destroy(): void
begin(): Tx begin(): Tx
makeInKeys(numKeys: number): string
} }
interface Tx { interface Tx {
query(sql: string, ...args:any): QueryResult query(sql: string, ...args: any): QueryResult
query1(sql: string, ...args:any): QueryResult1 query1(sql: string, ...args: any): QueryResult1
query11(sql: string, ...args:any): QueryResult11 query11(sql: string, ...args: any): QueryResult11
exec(sql: string, ...args:any): ExecResult exec(sql: string, ...args: any): ExecResult
insert(table: string, data:Object): ExecResult insert(table: string, data: Object): ExecResult
replace(table: string, data:Object): ExecResult replace(table: string, data: Object): ExecResult
update(table: string, data:Object, where: string, ...args:any): ExecResult update(table: string, data: Object, where: string, ...args: any): ExecResult
delete(table: string, where: string, ...args:any): ExecResult delete(table: string, where: string, ...args: any): ExecResult
end(ok:boolean): void end(ok: boolean): void
makeInKeys(numKeys: number): string
} }
interface QueryResult { interface QueryResult {