fusenapi/model/fsaddressmodel_gen.go

97 lines
3.5 KiB
Go
Raw Normal View History

2023-06-08 07:41:49 +00:00
// Code generated by goctl. DO NOT EDIT.
package model
import (
"context"
"database/sql"
"fmt"
"strings"
"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 (
fsAddressFieldNames = builder.RawFieldNames(&FsAddress{})
fsAddressRows = strings.Join(fsAddressFieldNames, ",")
fsAddressRowsExpectAutoSet = strings.Join(stringx.Remove(fsAddressFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
fsAddressRowsWithPlaceHolder = strings.Join(stringx.Remove(fsAddressFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
)
type (
fsAddressModel interface {
Insert(ctx context.Context, data *FsAddress) (sql.Result, error)
FindOne(ctx context.Context, id int64) (*FsAddress, error)
Update(ctx context.Context, data *FsAddress) error
Delete(ctx context.Context, id int64) error
}
defaultFsAddressModel struct {
conn sqlx.SqlConn
table string
}
FsAddress struct {
Id int64 `db:"id"`
UserId int64 `db:"user_id"` // 用户ID
Name string `db:"name"` // 地址名称
FirstName string `db:"first_name"` // FirstName
LastName string `db:"last_name"` // LastName
Mobile string `db:"mobile"` // 手机号码
Street string `db:"street"` // 街道
Suite string `db:"suite"` // 房号
City string `db:"city"` // 城市
State string `db:"state"` // 州名
Country string `db:"country"` // 国家
ZipCode string `db:"zip_code"` // 邮编
Status int64 `db:"status"` // 1正常 0异常
IsDefault int64 `db:"is_default"` // 1默认地址0非默认地址
}
)
func newFsAddressModel(conn sqlx.SqlConn) *defaultFsAddressModel {
return &defaultFsAddressModel{
conn: conn,
table: "`fs_address`",
}
}
func (m *defaultFsAddressModel) 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 *defaultFsAddressModel) FindOne(ctx context.Context, id int64) (*FsAddress, error) {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", fsAddressRows, m.table)
var resp FsAddress
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 *defaultFsAddressModel) Insert(ctx context.Context, data *FsAddress) (sql.Result, error) {
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, fsAddressRowsExpectAutoSet)
ret, err := m.conn.ExecCtx(ctx, query, data.UserId, data.Name, data.FirstName, data.LastName, data.Mobile, data.Street, data.Suite, data.City, data.State, data.Country, data.ZipCode, data.Status, data.IsDefault)
return ret, err
}
func (m *defaultFsAddressModel) Update(ctx context.Context, data *FsAddress) error {
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, fsAddressRowsWithPlaceHolder)
_, err := m.conn.ExecCtx(ctx, query, data.UserId, data.Name, data.FirstName, data.LastName, data.Mobile, data.Street, data.Suite, data.City, data.State, data.Country, data.ZipCode, data.Status, data.IsDefault, data.Id)
return err
}
func (m *defaultFsAddressModel) tableName() string {
return m.table
}