support makeER

This commit is contained in:
Star 2024-11-22 16:36:11 +08:00
parent 9cd64d91d0
commit cc8c502ec0
3 changed files with 25 additions and 11 deletions

20
db.go
View File

@ -181,18 +181,30 @@ func makeDBObject(conn *db.DB, tx *db.Tx) map[string]any {
if tx == nil { if tx == nil {
obj["make"] = func(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value { obj["make"] = func(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value {
args, conn, _, logger := initDBArgs(argsIn, vm, 1) args, conn, _, logger := initDBArgs(argsIn, vm, 1)
arg0 := args.Str(0) erDesc := args.Str(0)
tryFile := gojs.FindPath(vm, arg0) tryFile := gojs.FindPath(vm, erDesc)
if u.FileExists(tryFile) { if u.FileExists(tryFile) {
arg0 = u.ReadFileN(tryFile) erDesc = u.ReadFileN(tryFile)
} }
if err := dao.MakeDBFromDesc(conn, args.Str(0), logger); err == nil { if err := dao.MakeDBFromDesc(conn, erDesc, logger); err == nil {
return nil return nil
} else { } else {
panic(vm.NewGoError(err)) panic(vm.NewGoError(err))
} }
} }
obj["makeER"] = func(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value {
args, _, _, logger := initDBArgs(argsIn, vm, 1)
outputFile := args.Str(0)
erDesc := args.Str(1)
tryFile := gojs.FindPath(vm, erDesc)
if u.FileExists(tryFile) {
erDesc = u.ReadFileN(tryFile)
}
dao.MakeERFile(erDesc, "", outputFile, logger)
return nil
}
obj["destroy"] = func(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value { obj["destroy"] = func(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value {
_, conn, _, _ := initDBArgs(argsIn, vm, 0) _, conn, _, _ := initDBArgs(argsIn, vm, 0)
if err := conn.Destroy(); err == nil { if err := conn.Destroy(); err == nil {

2
db.ts
View File

@ -4,6 +4,7 @@ export default {
get, get,
setDefault, setDefault,
make, make,
makeER,
query, query,
query1, query1,
query11, query11,
@ -20,6 +21,7 @@ export default {
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 makeER(outputFile: string, descFileOrContent: string): void { }
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 }

14
go.mod
View File

@ -3,19 +3,19 @@ module apigo.cc/gojs/db
go 1.18 go 1.18
require ( require (
apigo.cc/gojs v0.0.4 apigo.cc/gojs v0.0.6
github.com/ssgo/dao v0.1.5 github.com/ssgo/dao v0.1.5
github.com/ssgo/db v1.7.11 github.com/ssgo/db v1.7.11
github.com/ssgo/log v1.7.7 github.com/ssgo/log v1.7.7
github.com/ssgo/u v1.7.9 github.com/ssgo/u v1.7.11
modernc.org/sqlite v1.33.1 modernc.org/sqlite v1.34.1
) )
require ( require (
filippo.io/edwards25519 v1.1.0 // indirect filippo.io/edwards25519 v1.1.0 // indirect
github.com/dlclark/regexp2 v1.11.4 // indirect github.com/dlclark/regexp2 v1.11.4 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect github.com/dustin/go-humanize v1.0.1 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/fsnotify/fsnotify v1.8.0 // indirect
github.com/go-sourcemap/sourcemap v2.1.4+incompatible // indirect github.com/go-sourcemap/sourcemap v2.1.4+incompatible // indirect
github.com/go-sql-driver/mysql v1.8.1 // indirect github.com/go-sql-driver/mysql v1.8.1 // indirect
github.com/google/pprof v0.0.0-20240409012703-83162a5b38cd // indirect github.com/google/pprof v0.0.0-20240409012703-83162a5b38cd // indirect
@ -25,11 +25,11 @@ require (
github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/ncruces/go-strftime v0.1.9 // indirect github.com/ncruces/go-strftime v0.1.9 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/ssgo/config v1.7.8 // indirect github.com/ssgo/config v1.7.9 // indirect
github.com/ssgo/standard v1.7.7 // indirect github.com/ssgo/standard v1.7.7 // indirect
github.com/ssgo/tool v0.4.27 // indirect github.com/ssgo/tool v0.4.27 // indirect
golang.org/x/sys v0.26.0 // indirect golang.org/x/sys v0.27.0 // indirect
golang.org/x/text v0.19.0 // indirect golang.org/x/text v0.20.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect
modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6 // indirect modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6 // indirect
modernc.org/libc v1.55.3 // indirect modernc.org/libc v1.55.3 // indirect