chore: update goctl interface{} to any (#2819)

* chore: update goctl interface{} to any

* chore: update goctl interface{} to any
This commit is contained in:
Kevin Wan
2023-01-24 17:51:03 +08:00
committed by GitHub
parent ae87114282
commit eab904af64
32 changed files with 112 additions and 112 deletions

View File

@@ -122,7 +122,7 @@ goctl model 为go-zero下的工具模块中的组件之一目前支持识别m
func (m *defaultUserModel) FindOneByUser(user string) (*User, error) {
userKey := fmt.Sprintf("%s%v", cacheUserPrefix, user)
var resp User
err := m.QueryRowIndex(&resp, userKey, m.formatPrimary, func(conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
err := m.QueryRowIndex(&resp, userKey, m.formatPrimary, func(conn sqlx.SqlConn, v any) (i any, e error) {
query := fmt.Sprintf("select %s from %s where user = ? limit 1", userRows, m.table)
if err := conn.QueryRow(&resp, query, user); err != nil {
return nil, err
@@ -142,7 +142,7 @@ goctl model 为go-zero下的工具模块中的组件之一目前支持识别m
func (m *defaultUserModel) FindOneByName(name string) (*User, error) {
userNameKey := fmt.Sprintf("%s%v", cacheUserNamePrefix, name)
var resp User
err := m.QueryRowIndex(&resp, userNameKey, m.formatPrimary, func(conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
err := m.QueryRowIndex(&resp, userNameKey, m.formatPrimary, func(conn sqlx.SqlConn, v any) (i any, e error) {
query := fmt.Sprintf("select %s from %s where name = ? limit 1", userRows, m.table)
if err := conn.QueryRow(&resp, query, name); err != nil {
return nil, err
@@ -162,7 +162,7 @@ goctl model 为go-zero下的工具模块中的组件之一目前支持识别m
func (m *defaultUserModel) FindOneByMobile(mobile string) (*User, error) {
userMobileKey := fmt.Sprintf("%s%v", cacheUserMobilePrefix, mobile)
var resp User
err := m.QueryRowIndex(&resp, userMobileKey, m.formatPrimary, func(conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
err := m.QueryRowIndex(&resp, userMobileKey, m.formatPrimary, func(conn sqlx.SqlConn, v any) (i any, e error) {
query := fmt.Sprintf("select %s from %s where mobile = ? limit 1", userRows, m.table)
if err := conn.QueryRow(&resp, query, mobile); err != nil {
return nil, err
@@ -205,11 +205,11 @@ goctl model 为go-zero下的工具模块中的组件之一目前支持识别m
return err
}
func (m *defaultUserModel) formatPrimary(primary interface{}) string {
func (m *defaultUserModel) formatPrimary(primary any) string {
return fmt.Sprintf("%s%v", cacheUserIdPrefix, primary)
}
func (m *defaultUserModel) queryPrimary(conn sqlx.SqlConn, v, primary interface{}) error {
func (m *defaultUserModel) queryPrimary(conn sqlx.SqlConn, v, primary any) error {
query := fmt.Sprintf("select %s from %s where id = ? limit 1", userRows, m.table)
return conn.QueryRow(v, query, primary)
}

View File

@@ -5,12 +5,12 @@ import (
)
// Deprecated: Use github.com/zeromicro/go-zero/core/stores/builder.RawFieldNames instead.
func FieldNames(in interface{}) []string {
func FieldNames(in any) []string {
return builder.RawFieldNames(in)
}
// Deprecated: Use github.com/zeromicro/go-zero/core/stores/builder.RawFieldNames instead.
func RawFieldNames(in interface{}, postgresSql ...bool) []string {
func RawFieldNames(in any, postgresSql ...bool) []string {
return builder.RawFieldNames(in, postgresSql...)
}

View File

@@ -33,7 +33,7 @@ func genDelete(table Table, withCache, postgreSql bool) (string, string, error)
output, err := util.With("delete").
Parse(text).
Execute(map[string]interface{}{
Execute(map[string]any{
"upperStartCamelObject": camel,
"withCache": withCache,
"containsIndexCache": table.ContainsUniqueCacheKey,
@@ -57,7 +57,7 @@ func genDelete(table Table, withCache, postgreSql bool) (string, string, error)
deleteMethodOut, err := util.With("deleteMethod").
Parse(text).
Execute(map[string]interface{}{
Execute(map[string]any{
"lowerStartCamelPrimaryKey": util.EscapeGolangKeyword(stringx.From(table.PrimaryKey.Name.ToCamel()).Untitle()),
"dataType": table.PrimaryKey.DataType,
"data": table,

View File

@@ -37,7 +37,7 @@ func genField(table Table, field *parser.Field) (string, error) {
output, err := util.With("types").
Parse(text).
Execute(map[string]interface{}{
Execute(map[string]any{
"name": util.SafeString(field.Name.ToCamel()),
"type": field.DataType,
"tag": tag,

View File

@@ -16,7 +16,7 @@ func genFindOne(table Table, withCache, postgreSql bool) (string, string, error)
output, err := util.With("findOne").
Parse(text).
Execute(map[string]interface{}{
Execute(map[string]any{
"withCache": withCache,
"upperStartCamelObject": camel,
"lowerStartCamelObject": stringx.From(camel).Untitle(),
@@ -39,7 +39,7 @@ func genFindOne(table Table, withCache, postgreSql bool) (string, string, error)
findOneMethod, err := util.With("findOneMethod").
Parse(text).
Execute(map[string]interface{}{
Execute(map[string]any{
"upperStartCamelObject": camel,
"lowerStartCamelPrimaryKey": util.EscapeGolangKeyword(stringx.From(table.PrimaryKey.Name.ToCamel()).Untitle()),
"dataType": table.PrimaryKey.DataType,

View File

@@ -28,7 +28,7 @@ func genFindOneByField(table Table, withCache, postgreSql bool) (*findOneCode, e
for _, key := range table.UniqueCacheKey {
in, paramJoinString, originalFieldString := convertJoin(key, postgreSql)
output, err := t.Execute(map[string]interface{}{
output, err := t.Execute(map[string]any{
"upperStartCamelObject": camelTableName,
"upperField": key.FieldNameJoin.Camel().With("").Source(),
"in": in,
@@ -68,7 +68,7 @@ func genFindOneByField(table Table, withCache, postgreSql bool) (*findOneCode, e
if len(inJoin) > 0 {
in = inJoin.With(", ").Source()
}
output, err := t.Execute(map[string]interface{}{
output, err := t.Execute(map[string]any{
"upperStartCamelObject": camelTableName,
"upperField": key.FieldNameJoin.Camel().With("").Source(),
"in": in,
@@ -88,7 +88,7 @@ func genFindOneByField(table Table, withCache, postgreSql bool) (*findOneCode, e
return nil, err
}
out, err := util.With("findOneByFieldExtraMethod").Parse(text).Execute(map[string]interface{}{
out, err := util.With("findOneByFieldExtraMethod").Parse(text).Execute(map[string]any{
"upperStartCamelObject": camelTableName,
"primaryKeyLeft": table.PrimaryCacheKey.VarLeft,
"lowerStartCamelObject": stringx.From(camelTableName).Untitle(),

View File

@@ -354,7 +354,7 @@ func (g *defaultGenerator) genModelCustom(in parser.Table, withCache bool) (stri
t := util.With("model-custom").
Parse(text).
GoFmt(true)
output, err := t.Execute(map[string]interface{}{
output, err := t.Execute(map[string]any{
"pkg": g.pkg,
"withCache": withCache,
"upperStartCamelObject": in.Name.ToCamel(),
@@ -375,7 +375,7 @@ func (g *defaultGenerator) executeModel(table Table, code *code) (*bytes.Buffer,
t := util.With("model").
Parse(text).
GoFmt(true)
output, err := t.Execute(map[string]interface{}{
output, err := t.Execute(map[string]any{
"pkg": g.pkg,
"imports": code.importsCode,
"vars": code.varsCode,

View File

@@ -30,7 +30,7 @@ func genImports(table Table, withCache, timeImport bool) (string, error) {
return "", err
}
buffer, err := util.With("import").Parse(text).Execute(map[string]interface{}{
buffer, err := util.With("import").Parse(text).Execute(map[string]any{
"time": timeImport,
"containsPQ": table.ContainsPQ,
"data": table,

View File

@@ -58,7 +58,7 @@ func genInsert(table Table, withCache, postgreSql bool) (string, string, error)
output, err := util.With("insert").
Parse(text).
Execute(map[string]interface{}{
Execute(map[string]any{
"withCache": withCache,
"upperStartCamelObject": camel,
"lowerStartCamelObject": stringx.From(camel).Untitle(),
@@ -78,7 +78,7 @@ func genInsert(table Table, withCache, postgreSql bool) (string, string, error)
return "", "", err
}
insertMethodOutput, err := util.With("insertMethod").Parse(text).Execute(map[string]interface{}{
insertMethodOutput, err := util.With("insertMethod").Parse(text).Execute(map[string]any{
"upperStartCamelObject": camel,
"data": table,
})

View File

@@ -21,7 +21,7 @@ func genNew(table Table, withCache, postgreSql bool) (string, error) {
output, err := util.With("new").
Parse(text).
Execute(map[string]interface{}{
Execute(map[string]any{
"table": t,
"withCache": withCache,
"upperStartCamelObject": table.Name.ToCamel(),

View File

@@ -14,7 +14,7 @@ func genTableName(table Table) (string, error) {
output, err := util.With("tableName").
Parse(text).
Execute(map[string]interface{}{
Execute(map[string]any{
"tableName": table.Name.Source(),
"upperStartCamelObject": table.Name.ToCamel(),
})

View File

@@ -16,7 +16,7 @@ func genTag(table Table, in string) (string, error) {
return "", err
}
output, err := util.With("tag").Parse(text).Execute(map[string]interface{}{
output, err := util.With("tag").Parse(text).Execute(map[string]any{
"field": in,
"data": table,
})

View File

@@ -21,7 +21,7 @@ func genTypes(table Table, methods string, withCache bool) (string, error) {
output, err := util.With("types").
Parse(text).
Execute(map[string]interface{}{
Execute(map[string]any{
"withCache": withCache,
"method": methods,
"upperStartCamelObject": table.Name.ToCamel(),

View File

@@ -95,7 +95,7 @@ func genUpdate(table Table, withCache, postgreSql bool) (
}
updateMethodOutput, err := util.With("updateMethod").Parse(text).Execute(
map[string]interface{}{
map[string]any{
"upperStartCamelObject": camelTableName,
"data": table,
},

View File

@@ -26,7 +26,7 @@ func genVars(table Table, withCache, postgreSql bool) (string, error) {
}
output, err := util.With("var").Parse(text).
GoFmt(true).Execute(map[string]interface{}{
GoFmt(true).Execute(map[string]any{
"lowerStartCamelObject": stringx.From(camel).Untitle(),
"upperStartCamelObject": camel,
"cacheKeys": strings.Join(keys, "\n"),

View File

@@ -24,14 +24,14 @@ type (
// DbColumn defines column info of columns
DbColumn struct {
Name string `db:"COLUMN_NAME"`
DataType string `db:"DATA_TYPE"`
ColumnType string `db:"COLUMN_TYPE"`
Extra string `db:"EXTRA"`
Comment string `db:"COLUMN_COMMENT"`
ColumnDefault interface{} `db:"COLUMN_DEFAULT"`
IsNullAble string `db:"IS_NULLABLE"`
OrdinalPosition int `db:"ORDINAL_POSITION"`
Name string `db:"COLUMN_NAME"`
DataType string `db:"DATA_TYPE"`
ColumnType string `db:"COLUMN_TYPE"`
Extra string `db:"EXTRA"`
Comment string `db:"COLUMN_COMMENT"`
ColumnDefault any `db:"COLUMN_DEFAULT"`
IsNullAble string `db:"IS_NULLABLE"`
OrdinalPosition int `db:"ORDINAL_POSITION"`
}
// DbIndex defines index of columns in information_schema.statistic

View File

@@ -112,7 +112,7 @@ func (m *PostgreSqlModel) getColumns(schema, table string, in []*PostgreColumn)
var list []*Column
for _, e := range in {
var dft interface{}
var dft any
if len(e.ColumnDefault.String) > 0 {
dft = e.ColumnDefault
}

View File

@@ -1,8 +1,8 @@
func (m *default{{.upperStartCamelObject}}Model) formatPrimary(primary interface{}) string {
func (m *default{{.upperStartCamelObject}}Model) formatPrimary(primary any) string {
return fmt.Sprintf("%s%v", {{.primaryKeyLeft}}, primary)
}
func (m *default{{.upperStartCamelObject}}Model) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary interface{}) error {
func (m *default{{.upperStartCamelObject}}Model) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary any) error {
query := fmt.Sprintf("select %s from %s where {{.originalPrimaryField}} = {{if .postgreSql}}$1{{else}}?{{end}} limit 1", {{.lowerStartCamelObject}}Rows, m.table )
return conn.QueryRowCtx(ctx, v, query, primary)
}

View File

@@ -1,7 +1,7 @@
func (m *default{{.upperStartCamelObject}}Model) FindOneBy{{.upperField}}(ctx context.Context, {{.in}}) (*{{.upperStartCamelObject}}, error) {
{{if .withCache}}{{.cacheKey}}
var resp {{.upperStartCamelObject}}
err := m.QueryRowIndexCtx(ctx, &resp, {{.cacheKeyVariable}}, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
err := m.QueryRowIndexCtx(ctx, &resp, {{.cacheKeyVariable}}, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v any) (i any, e error) {
query := fmt.Sprintf("select %s from %s where {{.originalField}} limit 1", {{.lowerStartCamelObject}}Rows, m.table)
if err := conn.QueryRowCtx(ctx, &resp, query, {{.lowerStartCamelField}}); err != nil {
return nil, err

View File

@@ -1,7 +1,7 @@
func (m *default{{.upperStartCamelObject}}Model) FindOne(ctx context.Context, {{.lowerStartCamelPrimaryKey}} {{.dataType}}) (*{{.upperStartCamelObject}}, error) {
{{if .withCache}}{{.cacheKey}}
var resp {{.upperStartCamelObject}}
err := m.QueryRowCtx(ctx, &resp, {{.cacheKeyVariable}}, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
err := m.QueryRowCtx(ctx, &resp, {{.cacheKeyVariable}}, func(ctx context.Context, conn sqlx.SqlConn, v any) error {
query := fmt.Sprintf("select %s from %s where {{.originalPrimaryKey}} = {{if .postgreSql}}$1{{else}}?{{end}} limit 1", {{.lowerStartCamelObject}}Rows, m.table)
return conn.QueryRowCtx(ctx, v, query, {{.lowerStartCamelPrimaryKey}})
})

View File

@@ -71,7 +71,7 @@ func (m *defaultStudentModel) Insert(data Student) (sql.Result, error) {
func (m *defaultStudentModel) FindOne(id int64) (*Student, error) {
studentIdKey := fmt.Sprintf("%s%v", cacheStudentIdPrefix, id)
var resp Student
err := m.QueryRow(&resp, studentIdKey, func(conn sqlx.SqlConn, v interface{}) error {
err := m.QueryRow(&resp, studentIdKey, func(conn sqlx.SqlConn, v any) error {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", studentRows, m.table)
return conn.QueryRow(v, query, id)
})
@@ -88,7 +88,7 @@ func (m *defaultStudentModel) FindOne(id int64) (*Student, error) {
func (m *defaultStudentModel) FindOneByClassName(class, name string) (*Student, error) {
studentClassNameKey := fmt.Sprintf("%s%v%v", cacheStudentClassNamePrefix, class, name)
var resp Student
err := m.QueryRowIndex(&resp, studentClassNameKey, m.formatPrimary, func(conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
err := m.QueryRowIndex(&resp, studentClassNameKey, m.formatPrimary, func(conn sqlx.SqlConn, v any) (i any, e error) {
query := fmt.Sprintf("select %s from %s where `class` = ? and `name` = ? limit 1", studentRows, m.table)
if err := conn.QueryRow(&resp, query, class, name); err != nil {
return nil, err
@@ -124,11 +124,11 @@ func (m *defaultStudentModel) Delete(id int64, className, studentName string) er
return err
}
func (m *defaultStudentModel) formatPrimary(primary interface{}) string {
func (m *defaultStudentModel) formatPrimary(primary any) string {
return fmt.Sprintf("%s%v", cacheStudentIdPrefix, primary)
}
func (m *defaultStudentModel) queryPrimary(conn sqlx.SqlConn, v, primary interface{}) error {
func (m *defaultStudentModel) queryPrimary(conn sqlx.SqlConn, v, primary any) error {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", studentRows, m.table)
return conn.QueryRow(v, query, primary)
}

View File

@@ -27,13 +27,13 @@ type rowsScanner interface {
Columns() ([]string, error)
Err() error
Next() bool
Scan(v ...interface{}) error
Scan(v ...any) error
}
func getTaggedFieldValueMap(v reflect.Value) (map[string]interface{}, error) {
func getTaggedFieldValueMap(v reflect.Value) (map[string]any, error) {
rt := mapping.Deref(v.Type())
size := rt.NumField()
result := make(map[string]interface{}, size)
result := make(map[string]any, size)
for i := 0; i < size; i++ {
key := parseTagName(rt.Field(i))
@@ -63,7 +63,7 @@ func getTaggedFieldValueMap(v reflect.Value) (map[string]interface{}, error) {
return result, nil
}
func mapStructFieldsIntoSlice(v reflect.Value, columns []string, strict bool) ([]interface{}, error) {
func mapStructFieldsIntoSlice(v reflect.Value, columns []string, strict bool) ([]any, error) {
fields := unwrapFields(v)
if strict && len(columns) < len(fields) {
return nil, ErrNotMatchDestination
@@ -74,7 +74,7 @@ func mapStructFieldsIntoSlice(v reflect.Value, columns []string, strict bool) ([
return nil, err
}
values := make([]interface{}, len(columns))
values := make([]any, len(columns))
if len(taggedMap) == 0 {
for i := 0; i < len(values); i++ {
valueField := fields[i]
@@ -100,7 +100,7 @@ func mapStructFieldsIntoSlice(v reflect.Value, columns []string, strict bool) ([
if tagged, ok := taggedMap[column]; ok {
values[i] = tagged
} else {
var anonymous interface{}
var anonymous any
values[i] = &anonymous
}
}
@@ -119,7 +119,7 @@ func parseTagName(field reflect.StructField) string {
return options[0]
}
func unmarshalRow(v interface{}, scanner rowsScanner, strict bool) error {
func unmarshalRow(v any, scanner rowsScanner, strict bool) error {
if !scanner.Next() {
if err := scanner.Err(); err != nil {
return err
@@ -161,7 +161,7 @@ func unmarshalRow(v interface{}, scanner rowsScanner, strict bool) error {
}
}
func unmarshalRows(v interface{}, scanner rowsScanner, strict bool) error {
func unmarshalRows(v any, scanner rowsScanner, strict bool) error {
rv := reflect.ValueOf(v)
if err := mapping.ValidatePtr(&rv); err != nil {
return err
@@ -181,7 +181,7 @@ func unmarshalRows(v interface{}, scanner rowsScanner, strict bool) error {
rve.Set(reflect.Append(rve, reflect.Indirect(item)))
}
}
fillFn := func(value interface{}) error {
fillFn := func(value any) error {
if rve.CanSet() {
if err := scanner.Scan(value); err != nil {
return err

View File

@@ -26,12 +26,12 @@ func NewMockConn(db *sql.DB) *MockConn {
}
// Exec executes sql and returns the result
func (conn *MockConn) Exec(query string, args ...interface{}) (sql.Result, error) {
func (conn *MockConn) Exec(query string, args ...any) (sql.Result, error) {
return exec(conn.db, query, args...)
}
// ExecCtx executes sql and returns the result
func (conn *MockConn) ExecCtx(_ context.Context, query string, args ...interface{}) (sql.Result, error) {
func (conn *MockConn) ExecCtx(_ context.Context, query string, args ...any) (sql.Result, error) {
return exec(conn.db, query, args...)
}
@@ -47,50 +47,50 @@ func (conn *MockConn) PrepareCtx(_ context.Context, query string) (sqlx.StmtSess
}
// QueryRow executes sql and returns a query row
func (conn *MockConn) QueryRow(v interface{}, q string, args ...interface{}) error {
func (conn *MockConn) QueryRow(v any, q string, args ...any) error {
return query(conn.db, func(rows *sql.Rows) error {
return unmarshalRow(v, rows, true)
}, q, args...)
}
// QueryRowCtx executes sql and returns a query row
func (conn *MockConn) QueryRowCtx(_ context.Context, v interface{}, query string, args ...interface{}) error {
func (conn *MockConn) QueryRowCtx(_ context.Context, v any, query string, args ...any) error {
return conn.QueryRow(v, query, args...)
}
// QueryRowPartial executes sql and returns a partial query row
func (conn *MockConn) QueryRowPartial(v interface{}, q string, args ...interface{}) error {
func (conn *MockConn) QueryRowPartial(v any, q string, args ...any) error {
return query(conn.db, func(rows *sql.Rows) error {
return unmarshalRow(v, rows, false)
}, q, args...)
}
// QueryRowPartialCtx executes sql and returns a partial query row
func (conn *MockConn) QueryRowPartialCtx(_ context.Context, v interface{}, query string, args ...interface{}) error {
func (conn *MockConn) QueryRowPartialCtx(_ context.Context, v any, query string, args ...any) error {
return conn.QueryRowPartial(v, query, args...)
}
// QueryRows executes sql and returns query rows
func (conn *MockConn) QueryRows(v interface{}, q string, args ...interface{}) error {
func (conn *MockConn) QueryRows(v any, q string, args ...any) error {
return query(conn.db, func(rows *sql.Rows) error {
return unmarshalRows(v, rows, true)
}, q, args...)
}
// QueryRowsCtx executes sql and returns query rows
func (conn *MockConn) QueryRowsCtx(_ context.Context, v interface{}, query string, args ...interface{}) error {
func (conn *MockConn) QueryRowsCtx(_ context.Context, v any, query string, args ...any) error {
return conn.QueryRows(v, query, args...)
}
// QueryRowsPartial executes sql and returns partial query rows
func (conn *MockConn) QueryRowsPartial(v interface{}, q string, args ...interface{}) error {
func (conn *MockConn) QueryRowsPartial(v any, q string, args ...any) error {
return query(conn.db, func(rows *sql.Rows) error {
return unmarshalRows(v, rows, false)
}, q, args...)
}
// QueryRowsPartialCtx executes sql and returns partial query rows
func (conn *MockConn) QueryRowsPartialCtx(_ context.Context, v interface{}, query string, args ...interface{}) error {
func (conn *MockConn) QueryRowsPartialCtx(_ context.Context, v any, query string, args ...any) error {
return conn.QueryRowsPartial(v, query, args...)
}
@@ -113,50 +113,50 @@ func (s statement) Close() error {
return s.stmt.Close()
}
func (s statement) Exec(args ...interface{}) (sql.Result, error) {
func (s statement) Exec(args ...any) (sql.Result, error) {
return execStmt(s.stmt, args...)
}
func (s statement) ExecCtx(_ context.Context, args ...interface{}) (sql.Result, error) {
func (s statement) ExecCtx(_ context.Context, args ...any) (sql.Result, error) {
return s.Exec(args...)
}
func (s statement) QueryRow(v interface{}, args ...interface{}) error {
func (s statement) QueryRow(v any, args ...any) error {
return queryStmt(s.stmt, func(rows *sql.Rows) error {
return unmarshalRow(v, rows, true)
}, args...)
}
func (s statement) QueryRowCtx(_ context.Context, v interface{}, args ...interface{}) error {
func (s statement) QueryRowCtx(_ context.Context, v any, args ...any) error {
return s.QueryRow(v, args...)
}
func (s statement) QueryRowPartial(v interface{}, args ...interface{}) error {
func (s statement) QueryRowPartial(v any, args ...any) error {
return queryStmt(s.stmt, func(rows *sql.Rows) error {
return unmarshalRow(v, rows, false)
}, args...)
}
func (s statement) QueryRowPartialCtx(_ context.Context, v interface{}, args ...interface{}) error {
func (s statement) QueryRowPartialCtx(_ context.Context, v any, args ...any) error {
return s.QueryRowPartial(v, args...)
}
func (s statement) QueryRows(v interface{}, args ...interface{}) error {
func (s statement) QueryRows(v any, args ...any) error {
return queryStmt(s.stmt, func(rows *sql.Rows) error {
return unmarshalRows(v, rows, true)
}, args...)
}
func (s statement) QueryRowsCtx(_ context.Context, v interface{}, args ...interface{}) error {
func (s statement) QueryRowsCtx(_ context.Context, v any, args ...any) error {
return s.QueryRows(v, args...)
}
func (s statement) QueryRowsPartial(v interface{}, args ...interface{}) error {
func (s statement) QueryRowsPartial(v any, args ...any) error {
return queryStmt(s.stmt, func(rows *sql.Rows) error {
return unmarshalRows(v, rows, false)
}, args...)
}
func (s statement) QueryRowsPartialCtx(_ context.Context, v interface{}, args ...interface{}) error {
func (s statement) QueryRowsPartialCtx(_ context.Context, v any, args ...any) error {
return s.QueryRowsPartial(v, args...)
}

View File

@@ -13,7 +13,7 @@ import (
const slowThreshold = time.Millisecond * 500
func exec(db *sql.DB, q string, args ...interface{}) (sql.Result, error) {
func exec(db *sql.DB, q string, args ...any) (sql.Result, error) {
tx, err := db.Begin()
if err != nil {
return nil, err
@@ -48,7 +48,7 @@ func exec(db *sql.DB, q string, args ...interface{}) (sql.Result, error) {
return result, err
}
func execStmt(conn *sql.Stmt, args ...interface{}) (sql.Result, error) {
func execStmt(conn *sql.Stmt, args ...any) (sql.Result, error) {
stmt := fmt.Sprint(args...)
startTime := timex.Now()
result, err := conn.Exec(args...)
@@ -65,7 +65,7 @@ func execStmt(conn *sql.Stmt, args ...interface{}) (sql.Result, error) {
return result, err
}
func query(db *sql.DB, scanner func(*sql.Rows) error, q string, args ...interface{}) error {
func query(db *sql.DB, scanner func(*sql.Rows) error, q string, args ...any) error {
tx, err := db.Begin()
if err != nil {
return err
@@ -102,7 +102,7 @@ func query(db *sql.DB, scanner func(*sql.Rows) error, q string, args ...interfac
return scanner(rows)
}
func queryStmt(conn *sql.Stmt, scanner func(*sql.Rows) error, args ...interface{}) error {
func queryStmt(conn *sql.Stmt, scanner func(*sql.Rows) error, args ...any) error {
stmt := fmt.Sprint(args...)
startTime := timex.Now()
rows, err := conn.Query(args...)

View File

@@ -41,7 +41,7 @@ func escape(input string) string {
return b.String()
}
func format(query string, args ...interface{}) (string, error) {
func format(query string, args ...any) (string, error) {
numArgs := len(args)
if numArgs == 0 {
return query, nil