| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- // Code generated by goctl. DO NOT EDIT.
- package model
- import (
- "context"
- "database/sql"
- "fmt"
- "strings"
- "time"
- "github.com/zeromicro/go-zero/core/stores/builder"
- "github.com/zeromicro/go-zero/core/stores/sqlc"
- "github.com/zeromicro/go-zero/core/stores/sqlx"
- "github.com/zeromicro/go-zero/core/stringx"
- )
- var (
- cbCustomerFieldNames = builder.RawFieldNames(&CbCustomer{})
- cbCustomerRows = strings.Join(cbCustomerFieldNames, ",")
- cbCustomerRowsExpectAutoSet = strings.Join(stringx.Remove(cbCustomerFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
- cbCustomerRowsWithPlaceHolder = strings.Join(stringx.Remove(cbCustomerFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
- )
- type (
- cbCustomerModel interface {
- Insert(ctx context.Context, data *CbCustomer) (sql.Result, error)
- FindOne(ctx context.Context, id int64) (*CbCustomer, error)
- Update(ctx context.Context, data *CbCustomer) error
- Delete(ctx context.Context, id int64) error
- }
- defaultCbCustomerModel struct {
- conn sqlx.SqlConn
- table string
- }
- CbCustomer struct {
- Id int64 `db:"id"`
- ExternalUserid string `db:"external_userid"` // 微信客户的external_userid
- Nickname string `db:"nickname"` // 昵称
- Avatar string `db:"avatar"` // 图片
- Gender int64 `db:"gender"` // 性别
- CreatedAt time.Time `db:"created_at"`
- UpdatedAt time.Time `db:"updated_at"`
- }
- )
- func newCbCustomerModel(conn sqlx.SqlConn) *defaultCbCustomerModel {
- return &defaultCbCustomerModel{
- conn: conn,
- table: "`cb_customer`",
- }
- }
- func (m *defaultCbCustomerModel) withSession(session sqlx.Session) *defaultCbCustomerModel {
- return &defaultCbCustomerModel{
- conn: sqlx.NewSqlConnFromSession(session),
- table: "`cb_customer`",
- }
- }
- func (m *defaultCbCustomerModel) 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 *defaultCbCustomerModel) FindOne(ctx context.Context, id int64) (*CbCustomer, error) {
- query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", cbCustomerRows, m.table)
- var resp CbCustomer
- err := m.conn.QueryRowCtx(ctx, &resp, query, id)
- switch err {
- case nil:
- return &resp, nil
- case sqlc.ErrNotFound:
- return nil, ErrNotFound
- default:
- return nil, err
- }
- }
- func (m *defaultCbCustomerModel) Insert(ctx context.Context, data *CbCustomer) (sql.Result, error) {
- query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?)", m.table, cbCustomerRowsExpectAutoSet)
- ret, err := m.conn.ExecCtx(ctx, query, data.ExternalUserid, data.Nickname, data.Avatar, data.Gender)
- return ret, err
- }
- func (m *defaultCbCustomerModel) Update(ctx context.Context, data *CbCustomer) error {
- query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, cbCustomerRowsWithPlaceHolder)
- _, err := m.conn.ExecCtx(ctx, query, data.ExternalUserid, data.Nickname, data.Avatar, data.Gender, data.Id)
- return err
- }
- func (m *defaultCbCustomerModel) tableName() string {
- return m.table
- }
|