// Code generated by goctl. DO NOT EDIT. // versions: // goctl version: 1.7.3 package model 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 ( nhTouristBindFieldNames = builder.RawFieldNames(&NhTouristBind{}) nhTouristBindRows = strings.Join(nhTouristBindFieldNames, ",") nhTouristBindRowsExpectAutoSet = strings.Join(stringx.Remove(nhTouristBindFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",") nhTouristBindRowsWithPlaceHolder = strings.Join(stringx.Remove(nhTouristBindFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?" ) type ( nhTouristBindModel interface { Insert(ctx context.Context, data *NhTouristBind) (sql.Result, error) FindOne(ctx context.Context, id int) (*NhTouristBind, error) Update(ctx context.Context, data *NhTouristBind) error Delete(ctx context.Context, id int) error } defaultNhTouristBindModel struct { conn sqlx.SqlConn table string } NhTouristBind struct { Id int `db:"id"` TouristAccount string `db:"tourist_account"` // 游客账号 FormalAccount string `db:"formal_account"` // 正式账号 CreateTime int `db:"create_time"` // 创建时间 Uid uint `db:"uid"` // 用户ID } ) func newNhTouristBindModel(conn sqlx.SqlConn) *defaultNhTouristBindModel { return &defaultNhTouristBindModel{ conn: conn, table: "`nh_tourist_bind`", } } func (m *defaultNhTouristBindModel) Delete(ctx context.Context, id int) error { query := fmt.Sprintf("delete from %s where `id` = ?", m.table) _, err := m.conn.ExecCtx(ctx, query, id) return err } func (m *defaultNhTouristBindModel) FindOne(ctx context.Context, id int) (*NhTouristBind, error) { query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", nhTouristBindRows, m.table) var resp NhTouristBind 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 *defaultNhTouristBindModel) Insert(ctx context.Context, data *NhTouristBind) (sql.Result, error) { query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?)", m.table, nhTouristBindRowsExpectAutoSet) ret, err := m.conn.ExecCtx(ctx, query, data.TouristAccount, data.FormalAccount, data.Uid) return ret, err } func (m *defaultNhTouristBindModel) Update(ctx context.Context, data *NhTouristBind) error { query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, nhTouristBindRowsWithPlaceHolder) _, err := m.conn.ExecCtx(ctx, query, data.TouristAccount, data.FormalAccount, data.Uid, data.Id) return err } func (m *defaultNhTouristBindModel) tableName() string { return m.table }