update for ssgo/dao

This commit is contained in:
Star 2025-07-15 17:18:36 +08:00
parent 195cbc6b59
commit 3a991746ad
5 changed files with 29 additions and 12 deletions

6
db.go
View File

@ -241,11 +241,15 @@ data t
args, _, _, logger := initDBArgs(argsIn, vm, 1) args, _, _, logger := initDBArgs(argsIn, vm, 1)
outputFile := args.Str(0) outputFile := args.Str(0)
erDesc := args.Str(1) erDesc := args.Str(1)
dbType := args.Str(2)
if dbType == "" {
dbType = "mysql"
}
tryFile := gojs.FindPath(vm, erDesc) tryFile := gojs.FindPath(vm, erDesc)
if u.FileExists(tryFile) { if u.FileExists(tryFile) {
erDesc = u.ReadFileN(tryFile) erDesc = u.ReadFileN(tryFile)
} }
dao.MakeERFile(erDesc, "", outputFile, logger) dao.MakeERFile(dbType, erDesc, "", outputFile, logger)
return nil return nil
} }

2
db.ts
View File

@ -22,7 +22,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): Object[] { return null as any } function make(descFileOrContent: string): Object[] { return null as any }
function makeER(outputFile: string, descFileOrContent: string): void { } function makeER(outputFile: string, descFileOrContent: string, dbType: string = 'mysql'): void { }
function query(sql: string, ...args: any): QueryResult { return null as any } function query(sql: string, ...args: any): QueryResult { return null as any }
function querya(sql: string, ...args: any): QueryResultA { 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 query1(sql: string, ...args: any): QueryResult1 { return null as any }

View File

@ -6,13 +6,14 @@ import (
"testing" "testing"
"apigo.cc/gojs" "apigo.cc/gojs"
_ "apigo.cc/gojs/console"
_ "apigo.cc/gojs/db" _ "apigo.cc/gojs/db"
"github.com/ssgo/u" "github.com/ssgo/u"
_ "modernc.org/sqlite" _ "modernc.org/sqlite"
) )
func Test(t *testing.T) { func Test(t *testing.T) {
// gojs.ExportForDev() gojs.ExportForDev()
defer os.Remove("test.db") defer os.Remove("test.db")
r, err := gojs.RunFile("db_test.js", "Tom") r, err := gojs.RunFile("db_test.js", "Tom")
if err != nil { if err != nil {

View File

@ -1,4 +1,5 @@
import db from 'apigo.cc/gojs/db' import db from 'apigo.cc/gojs/db'
import co from 'apigo.cc/gojs/console'
function main(testUserName) { function main(testUserName) {
db.setDefault('sqlite://test.db') db.setDefault('sqlite://test.db')
@ -15,5 +16,15 @@ function main(testUserName) {
`) `)
db.insert('User', { name: testUserName }) db.insert('User', { name: testUserName })
let user = db.query1('SELECT * FROM User').result let user = db.query1('SELECT * FROM User').result
let r = db.query1('SELECT * FROM User WHERE name = ?', testUserName)
co.info(r)
// db.delete('User', "name=?", testUserName)
db.insert('_deleted', { table: 'User', id: r.result.id })
r = db.query('SELECT * FROM _deleted')
co.info(r)
return user return user
} }

19
go.mod
View File

@ -3,11 +3,12 @@ module apigo.cc/gojs/db
go 1.23.0 go 1.23.0
require ( require (
apigo.cc/gojs v0.0.15 apigo.cc/gojs v0.0.17
github.com/ssgo/dao v0.1.7 apigo.cc/gojs/console v0.0.2
github.com/ssgo/db v1.7.12 github.com/ssgo/dao v0.1.12
github.com/ssgo/db v1.7.13
github.com/ssgo/log v1.7.7 github.com/ssgo/log v1.7.7
github.com/ssgo/u v1.7.19 github.com/ssgo/u v1.7.20
modernc.org/sqlite v1.38.0 modernc.org/sqlite v1.38.0
) )
@ -18,7 +19,7 @@ require (
github.com/fsnotify/fsnotify v1.9.0 // indirect github.com/fsnotify/fsnotify v1.9.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.9.3 // indirect github.com/go-sql-driver/mysql v1.9.3 // indirect
github.com/google/pprof v0.0.0-20250607225305-033d6d78b36a // indirect github.com/google/pprof v0.0.0-20250630185457-6e76a2b096b5 // indirect
github.com/google/uuid v1.6.0 // indirect github.com/google/uuid v1.6.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect
@ -27,11 +28,11 @@ require (
github.com/ssgo/config v1.7.9 // 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.29 // indirect github.com/ssgo/tool v0.4.29 // indirect
golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b // indirect golang.org/x/exp v0.0.0-20250711185948-6ae5c78190dc // indirect
golang.org/x/sys v0.33.0 // indirect golang.org/x/sys v0.34.0 // indirect
golang.org/x/text v0.26.0 // indirect golang.org/x/text v0.27.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect
modernc.org/libc v1.66.1 // indirect modernc.org/libc v1.66.3 // indirect
modernc.org/mathutil v1.7.1 // indirect modernc.org/mathutil v1.7.1 // indirect
modernc.org/memory v1.11.0 // indirect modernc.org/memory v1.11.0 // indirect
) )