[feat] 丰富错误提示信息

This commit is contained in:
what 2023-07-30 19:12:56 +08:00
parent e24dea4e1e
commit 42b16293b4
2 changed files with 14 additions and 2 deletions

10
builder_test.go Normal file
View File

@ -0,0 +1,10 @@
package db
import "testing"
func TestJoinSub(t *testing.T) {
b := NewBuilder(conn)
b.Grammar = &Sqlite3Grammar{}
t.Log(b.On("Select 1 as a, 2 as b", "t1", "true").ToSql())
}

View File

@ -6,6 +6,8 @@ import (
"errors" "errors"
"fmt" "fmt"
"reflect" "reflect"
"github.com/samber/lo"
) )
type RowScan struct { type RowScan struct {
@ -139,7 +141,7 @@ func sStructSlice(rows *sql.Rows, dest any) (result RowScan) {
if data := *scanArgs[i].(*[]uint8); len(data) > 0 { if data := *scanArgs[i].(*[]uint8); len(data) > 0 {
v := rv.Addr().Interface() v := rv.Addr().Interface()
if err := json.Unmarshal(data, &v); err != nil { if err := json.Unmarshal(data, &v); err != nil {
panic(fmt.Sprintf("[%s:%v] => %s", rv.Kind(), data, err)) panic(fmt.Sprintf("[%s:%s:%s] => %s", lo.Must1(lo.FindKey(keys, i)), rv.Kind(), data, err))
} }
} }
} }
@ -213,7 +215,7 @@ func sStruct(rows *sql.Rows, dest any) (result RowScan) {
if data := *scanArgs[i].(*[]uint8); len(data) > 0 { if data := *scanArgs[i].(*[]uint8); len(data) > 0 {
v := rv.Addr().Interface() v := rv.Addr().Interface()
if err := json.Unmarshal(data, &v); err != nil { if err := json.Unmarshal(data, &v); err != nil {
panic(fmt.Sprintf("[%s:%v] => %s", rv.Kind(), data, err)) panic(fmt.Sprintf("[%s:%s:%s] => %s", lo.Must1(lo.FindKey(keys, i)), rv.Kind(), data, err))
} }
} }
} }