Skip to content

Commit

Permalink
Merge pull request #87 from xushiwei/ydb
Browse files Browse the repository at this point in the history
rm ast.Node
  • Loading branch information
xushiwei authored Feb 14, 2024
2 parents 9321fa7 + 7732e1f commit 1159369
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 103 deletions.
19 changes: 3 additions & 16 deletions ydb/class.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"reflect"
"runtime/debug"

"github.com/goplus/gop/ast"
"github.com/goplus/yap/test"
"github.com/goplus/yap/test/logt"
)
Expand Down Expand Up @@ -65,7 +64,7 @@ func (p *Class) t() test.CaseT {
}

// Use sets the default table used in following sql operations.
func (p *Class) Use(table string, src ...ast.Expr) {
func (p *Class) Use(table string) {
_, ok := p.tables[table]
if !ok {
log.Panicln("table not found:", table)
Expand All @@ -74,7 +73,7 @@ func (p *Class) Use(table string, src ...ast.Expr) {
}

// OnErr sets error processing of a sql execution.
func (p *Class) OnErr(onErr func(error), src ...ast.Expr) {
func (p *Class) OnErr(onErr func(error)) {
p.onErr = onErr
}

Expand All @@ -96,22 +95,10 @@ func (p *Class) handleErr(prompt string, err error) {
//
// For checking call result:
// - ret <expr1>, <expr2>, ...
func (p *Class) Ret__0(src ast.Expr, args ...any) {
func (p *Class) Ret(args ...any) {
if p.ret == nil {
log.Panicln("please call `ret` after a `query` or `call` statement")
}
if src == nil {
if len(args) == 0 {
p.ret(nil)
return
}
args = append(make([]any, 1, len(args)+1), args...)
}
p.ret(args...)
}

// Ret checks a query or call result.
func (p *Class) Ret__1(args ...any) {
p.ret(args...)
}

Expand Down
6 changes: 2 additions & 4 deletions ydb/classfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import (
"log"
"reflect"
"strings"

"github.com/goplus/gop/ast"
)

const (
Expand Down Expand Up @@ -54,7 +52,7 @@ func (p *Sql) initSql() {
}

// Engine initializes database by specified engine name.
func (p *Sql) Engine__0(name string, src ...ast.Expr) {
func (p *Sql) Engine__0(name string) {
driver, ok := engines[name]
if !ok {
log.Panicf("engine `%s` not found: please call ydb.Register first\n", name)
Expand Down Expand Up @@ -114,7 +112,7 @@ func dbName(fldName string) string {
}

// Table creates a new table by specified Schema.
func Gopt_Sql_Gopx_Table[Schema any](sql interface{ defineTable(string, any) }, nameVer string, src ...ast.Expr) {
func Gopt_Sql_Gopx_Table[Schema any](sql interface{ defineTable(string, any) }, nameVer string) {
sql.defineTable(nameVer, (*Schema)(nil))
}

Expand Down
10 changes: 1 addition & 9 deletions ydb/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@ import (
"database/sql"
"log"
"reflect"

"github.com/goplus/gop/ast"
)

// -----------------------------------------------------------------------------

// Delete deltes rows by cond.
// - delete <cond>, <arg1>, <arg2>, ...
func (p *Class) Delete__0(src ast.Expr, cond string, args ...any) (sql.Result, error) {
func (p *Class) Delete(cond string, args ...any) (sql.Result, error) {
tbl := p.exprTblname(cond)
query := makeDeleteExpr(tbl, cond)
iArgSlice := checkArgSlice(args)
Expand All @@ -39,12 +37,6 @@ func (p *Class) Delete__0(src ast.Expr, cond string, args ...any) (sql.Result, e
return p.deleteOne(context.TODO(), query, args)
}

// Delete deltes rows by cond.
// - delete <cond>, <arg1>, <arg2>, ...
func (p *Class) Delete__1(cond string, args ...any) (sql.Result, error) {
return p.Delete__0(nil, cond, args...)
}

func makeDeleteExpr(tbl string, cond string) string {
query := make([]byte, 0, 64)
query = append(query, "DELETE FROM "...)
Expand Down
80 changes: 40 additions & 40 deletions ydb/demo/foo/gop_autogen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 1 addition & 12 deletions ydb/insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import (
"log"
"reflect"
"strings"

"github.com/goplus/gop/ast"
)

// -----------------------------------------------------------------------------
Expand All @@ -33,7 +31,7 @@ import (
// - insert <colName1>, <valSlice1>, <colName2>, <valSlice2>, ...
// - insert <structValOrPtr>
// - insert <structOrPtrSlice>
func (p *Class) Insert__0(src ast.Expr, args ...any) (sql.Result, error) {
func (p *Class) Insert(args ...any) (sql.Result, error) {
if p.tbl == "" {
log.Panicln("please call `use <tableName>` to specified current table")
}
Expand All @@ -44,15 +42,6 @@ func (p *Class) Insert__0(src ast.Expr, args ...any) (sql.Result, error) {
return p.insertKvPair(args...)
}

// Insert inserts new rows.
// - insert <colName1>, <val1>, <colName2>, <val2>, ...
// - insert <colName1>, <valSlice1>, <colName2>, <valSlice2>, ...
// - insert <structValOrPtr>
// - insert <structOrPtrSlice>
func (p *Class) Insert__1(kvPair ...any) (sql.Result, error) {
return p.Insert__0(nil, kvPair...)
}

// Insert inserts a new row.
// - insert <structValOrPtr>
// - insert <structOrPtrSlice>
Expand Down
Loading

0 comments on commit 1159369

Please sign in to comment.