From cc8c502ec0768c62491f4bb0f05c9ab8dab724a1 Mon Sep 17 00:00:00 2001 From: Star <> Date: Fri, 22 Nov 2024 16:36:11 +0800 Subject: [PATCH] support makeER --- db.go | 20 ++++++++++++++++---- db.ts | 2 ++ go.mod | 14 +++++++------- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/db.go b/db.go index 8f1927b..3e88f28 100644 --- a/db.go +++ b/db.go @@ -181,18 +181,30 @@ func makeDBObject(conn *db.DB, tx *db.Tx) map[string]any { if tx == nil { obj["make"] = func(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value { args, conn, _, logger := initDBArgs(argsIn, vm, 1) - arg0 := args.Str(0) - tryFile := gojs.FindPath(vm, arg0) + erDesc := args.Str(0) + tryFile := gojs.FindPath(vm, erDesc) 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 } else { 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 { _, conn, _, _ := initDBArgs(argsIn, vm, 0) if err := conn.Destroy(); err == nil { diff --git a/db.ts b/db.ts index 9a8e84d..a86f4e9 100644 --- a/db.ts +++ b/db.ts @@ -4,6 +4,7 @@ export default { get, setDefault, make, + makeER, query, query1, query11, @@ -20,6 +21,7 @@ export default { function get(dbName: string): DB { return null as any } function setDefault(dbName: string): void { } function make(descFileOrContent: string): Array { 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 } function query11(sql: string, ...args: any): QueryResult11 { return null as any } diff --git a/go.mod b/go.mod index aee76d7..327b92c 100644 --- a/go.mod +++ b/go.mod @@ -3,19 +3,19 @@ module apigo.cc/gojs/db go 1.18 require ( - apigo.cc/gojs v0.0.4 + apigo.cc/gojs v0.0.6 github.com/ssgo/dao v0.1.5 github.com/ssgo/db v1.7.11 github.com/ssgo/log v1.7.7 - github.com/ssgo/u v1.7.9 - modernc.org/sqlite v1.33.1 + github.com/ssgo/u v1.7.11 + modernc.org/sqlite v1.34.1 ) require ( filippo.io/edwards25519 v1.1.0 // indirect github.com/dlclark/regexp2 v1.11.4 // 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-sql-driver/mysql v1.8.1 // 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/ncruces/go-strftime v0.1.9 // 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/tool v0.4.27 // indirect - golang.org/x/sys v0.26.0 // indirect - golang.org/x/text v0.19.0 // indirect + golang.org/x/sys v0.27.0 // indirect + golang.org/x/text v0.20.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6 // indirect modernc.org/libc v1.55.3 // indirect