113 lines
4.4 KiB
Go
113 lines
4.4 KiB
Go
// Code generated by goctl. DO NOT EDIT.
|
|
// versions:
|
|
// goctl version: 1.7.5
|
|
|
|
package model
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/zeromicro/go-zero/core/stores/builder"
|
|
"github.com/zeromicro/go-zero/core/stores/cache"
|
|
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
"github.com/zeromicro/go-zero/core/stringx"
|
|
)
|
|
|
|
var (
|
|
douyinEcpmConfigFieldNames = builder.RawFieldNames(&DouyinEcpmConfig{})
|
|
douyinEcpmConfigRows = strings.Join(douyinEcpmConfigFieldNames, ",")
|
|
douyinEcpmConfigRowsExpectAutoSet = strings.Join(stringx.Remove(douyinEcpmConfigFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
|
douyinEcpmConfigRowsWithPlaceHolder = strings.Join(stringx.Remove(douyinEcpmConfigFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
|
|
|
cacheEcpmDouyinEcpmConfigIdPrefix = "cache:ecpm:douyinEcpmConfig:id:"
|
|
)
|
|
|
|
type (
|
|
douyinEcpmConfigModel interface {
|
|
Insert(ctx context.Context, data *DouyinEcpmConfig) (sql.Result, error)
|
|
FindOne(ctx context.Context, id uint64) (*DouyinEcpmConfig, error)
|
|
Update(ctx context.Context, data *DouyinEcpmConfig) error
|
|
Delete(ctx context.Context, id uint64) error
|
|
}
|
|
|
|
defaultDouyinEcpmConfigModel struct {
|
|
sqlc.CachedConn
|
|
table string
|
|
}
|
|
|
|
DouyinEcpmConfig struct {
|
|
Id uint64 `db:"id"`
|
|
AppAccountId uint64 `db:"app_account_id"`
|
|
EcpmValue uint64 `db:"ecpm_value"` // 值
|
|
EcpmView uint64 `db:"ecpm_view"` // 浏览次数
|
|
}
|
|
)
|
|
|
|
func newDouyinEcpmConfigModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) *defaultDouyinEcpmConfigModel {
|
|
return &defaultDouyinEcpmConfigModel{
|
|
CachedConn: sqlc.NewConn(conn, c, opts...),
|
|
table: "`douyin_ecpm_config`",
|
|
}
|
|
}
|
|
|
|
func (m *defaultDouyinEcpmConfigModel) Delete(ctx context.Context, id uint64) error {
|
|
ecpmDouyinEcpmConfigIdKey := fmt.Sprintf("%s%v", cacheEcpmDouyinEcpmConfigIdPrefix, id)
|
|
_, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
|
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
|
|
return conn.ExecCtx(ctx, query, id)
|
|
}, ecpmDouyinEcpmConfigIdKey)
|
|
return err
|
|
}
|
|
|
|
func (m *defaultDouyinEcpmConfigModel) FindOne(ctx context.Context, id uint64) (*DouyinEcpmConfig, error) {
|
|
ecpmDouyinEcpmConfigIdKey := fmt.Sprintf("%s%v", cacheEcpmDouyinEcpmConfigIdPrefix, id)
|
|
var resp DouyinEcpmConfig
|
|
err := m.QueryRowCtx(ctx, &resp, ecpmDouyinEcpmConfigIdKey, func(ctx context.Context, conn sqlx.SqlConn, v any) error {
|
|
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", douyinEcpmConfigRows, m.table)
|
|
return conn.QueryRowCtx(ctx, v, query, id)
|
|
})
|
|
switch err {
|
|
case nil:
|
|
return &resp, nil
|
|
case sqlc.ErrNotFound:
|
|
return nil, ErrNotFound
|
|
default:
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
func (m *defaultDouyinEcpmConfigModel) Insert(ctx context.Context, data *DouyinEcpmConfig) (sql.Result, error) {
|
|
ecpmDouyinEcpmConfigIdKey := fmt.Sprintf("%s%v", cacheEcpmDouyinEcpmConfigIdPrefix, data.Id)
|
|
ret, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
|
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?)", m.table, douyinEcpmConfigRowsExpectAutoSet)
|
|
return conn.ExecCtx(ctx, query, data.AppAccountId, data.EcpmValue, data.EcpmView)
|
|
}, ecpmDouyinEcpmConfigIdKey)
|
|
return ret, err
|
|
}
|
|
|
|
func (m *defaultDouyinEcpmConfigModel) Update(ctx context.Context, data *DouyinEcpmConfig) error {
|
|
ecpmDouyinEcpmConfigIdKey := fmt.Sprintf("%s%v", cacheEcpmDouyinEcpmConfigIdPrefix, data.Id)
|
|
_, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
|
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, douyinEcpmConfigRowsWithPlaceHolder)
|
|
return conn.ExecCtx(ctx, query, data.AppAccountId, data.EcpmValue, data.EcpmView, data.Id)
|
|
}, ecpmDouyinEcpmConfigIdKey)
|
|
return err
|
|
}
|
|
|
|
func (m *defaultDouyinEcpmConfigModel) formatPrimary(primary any) string {
|
|
return fmt.Sprintf("%s%v", cacheEcpmDouyinEcpmConfigIdPrefix, primary)
|
|
}
|
|
|
|
func (m *defaultDouyinEcpmConfigModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary any) error {
|
|
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", douyinEcpmConfigRows, m.table)
|
|
return conn.QueryRowCtx(ctx, v, query, primary)
|
|
}
|
|
|
|
func (m *defaultDouyinEcpmConfigModel) tableName() string {
|
|
return m.table
|
|
}
|