// 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 ( dcDeviceRelationFieldNames = builder.RawFieldNames(&DcDeviceRelation{}) dcDeviceRelationRows = strings.Join(dcDeviceRelationFieldNames, ",") dcDeviceRelationRowsExpectAutoSet = strings.Join(stringx.Remove(dcDeviceRelationFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",") dcDeviceRelationRowsWithPlaceHolder = strings.Join(stringx.Remove(dcDeviceRelationFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?" ) type ( dcDeviceRelationModel interface { Insert(ctx context.Context, data *DcDeviceRelation) (sql.Result, error) FindOne(ctx context.Context, id int64) (*DcDeviceRelation, error) FindOneByProjectIdDeviceCode(ctx context.Context, projectId int64, deviceCode string) (*DcDeviceRelation, error) Update(ctx context.Context, data *DcDeviceRelation) error Delete(ctx context.Context, id int64) error } defaultDcDeviceRelationModel struct { conn sqlx.SqlConn table string } DcDeviceRelation struct { Id int64 `db:"id"` ProjectId int64 `db:"project_id"` DeviceCode string `db:"device_code"` Chest string `db:"chest"` // 与之相关的 chest 设备 Pump string `db:"pump"` // 与之相关的 pump 设备 Value string `db:"value"` // 与之相关的 value 设备 } ) func newDcDeviceRelationModel(conn sqlx.SqlConn) *defaultDcDeviceRelationModel { return &defaultDcDeviceRelationModel{ conn: conn, table: "`dc_device_relation`", } } func (m *defaultDcDeviceRelationModel) withSession(session sqlx.Session) *defaultDcDeviceRelationModel { return &defaultDcDeviceRelationModel{ conn: sqlx.NewSqlConnFromSession(session), table: "`dc_device_relation`", } } func (m *defaultDcDeviceRelationModel) 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 *defaultDcDeviceRelationModel) FindOne(ctx context.Context, id int64) (*DcDeviceRelation, error) { query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", dcDeviceRelationRows, m.table) var resp DcDeviceRelation 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 *defaultDcDeviceRelationModel) FindOneByProjectIdDeviceCode(ctx context.Context, projectId int64, deviceCode string) (*DcDeviceRelation, error) { var resp DcDeviceRelation query := fmt.Sprintf("select %s from %s where `project_id` = ? and `device_code` = ? limit 1", dcDeviceRelationRows, m.table) err := m.conn.QueryRowCtx(ctx, &resp, query, projectId, deviceCode) switch err { case nil: return &resp, nil case sqlc.ErrNotFound: return nil, ErrNotFound default: return nil, err } } func (m *defaultDcDeviceRelationModel) Insert(ctx context.Context, data *DcDeviceRelation) (sql.Result, error) { query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?)", m.table, dcDeviceRelationRowsExpectAutoSet) ret, err := m.conn.ExecCtx(ctx, query, data.ProjectId, data.DeviceCode, data.Chest, data.Pump, data.Value) return ret, err } func (m *defaultDcDeviceRelationModel) Update(ctx context.Context, newData *DcDeviceRelation) error { query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, dcDeviceRelationRowsWithPlaceHolder) _, err := m.conn.ExecCtx(ctx, query, newData.ProjectId, newData.DeviceCode, newData.Chest, newData.Pump, newData.Value, newData.Id) return err } func (m *defaultDcDeviceRelationModel) tableName() string { return m.table }