88 lines
2.7 KiB
Go
88 lines
2.7 KiB
Go
// Code generated by goctl. DO NOT EDIT.
|
|
// versions:
|
|
// goctl version: 1.7.6
|
|
|
|
package config_api
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/zeromicro/go-zero/core/stores/builder"
|
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
"github.com/zeromicro/go-zero/core/stringx"
|
|
)
|
|
|
|
var (
|
|
configApiFieldNames = builder.RawFieldNames(&ConfigApi{})
|
|
configApiRows = strings.Join(configApiFieldNames, ",")
|
|
configApiRowsExpectAutoSet = strings.Join(stringx.Remove(configApiFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
|
configApiRowsWithPlaceHolder = strings.Join(stringx.Remove(configApiFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
|
)
|
|
|
|
type (
|
|
configApiModel interface {
|
|
Insert(ctx context.Context, data *ConfigApi) (sql.Result, error)
|
|
FindOne(ctx context.Context, id int64) (*ConfigApi, error)
|
|
Update(ctx context.Context, data *ConfigApi) error
|
|
Delete(ctx context.Context, id int64) error
|
|
}
|
|
|
|
defaultConfigApiModel struct {
|
|
conn sqlx.SqlConn
|
|
table string
|
|
}
|
|
|
|
ConfigApi struct {
|
|
Id int64 `db:"id"` // 主键ID
|
|
Type string `db:"type"` // 接口类型 0:172
|
|
Key sql.NullString `db:"key"` // key
|
|
Secret sql.NullString `db:"secret"` // 密钥
|
|
}
|
|
)
|
|
|
|
func newConfigApiModel(conn sqlx.SqlConn) *defaultConfigApiModel {
|
|
return &defaultConfigApiModel{
|
|
conn: conn,
|
|
table: "`config_api`",
|
|
}
|
|
}
|
|
|
|
func (m *defaultConfigApiModel) Delete(ctx context.Context, id int64) error {
|
|
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
|
|
_, err := m.conn.ExecCtx(ctx, query, id)
|
|
return err
|
|
}
|
|
|
|
func (m *defaultConfigApiModel) FindOne(ctx context.Context, id int64) (*ConfigApi, error) {
|
|
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", configApiRows, m.table)
|
|
var resp ConfigApi
|
|
err := m.conn.QueryRowCtx(ctx, &resp, query, id)
|
|
switch err {
|
|
case nil:
|
|
return &resp, nil
|
|
case sqlx.ErrNotFound:
|
|
return nil, ErrNotFound
|
|
default:
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
func (m *defaultConfigApiModel) Insert(ctx context.Context, data *ConfigApi) (sql.Result, error) {
|
|
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?)", m.table, configApiRowsExpectAutoSet)
|
|
ret, err := m.conn.ExecCtx(ctx, query, data.Type, data.Key, data.Secret)
|
|
return ret, err
|
|
}
|
|
|
|
func (m *defaultConfigApiModel) Update(ctx context.Context, data *ConfigApi) error {
|
|
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, configApiRowsWithPlaceHolder)
|
|
_, err := m.conn.ExecCtx(ctx, query, data.Type, data.Key, data.Secret, data.Id)
|
|
return err
|
|
}
|
|
|
|
func (m *defaultConfigApiModel) tableName() string {
|
|
return m.table
|
|
}
|