// 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/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 ( scNodeLabelInfoFieldNames = builder.RawFieldNames(&ScNodeLabelInfo{}) scNodeLabelInfoRows = strings.Join(scNodeLabelInfoFieldNames, ",") scNodeLabelInfoRowsExpectAutoSet = strings.Join(stringx.Remove(scNodeLabelInfoFieldNames, "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",") scNodeLabelInfoRowsWithPlaceHolder = strings.Join(stringx.Remove(scNodeLabelInfoFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?" cachePcmScNodeLabelInfoIdPrefix = "cache:pcm:scNodeLabelInfo:id:" ) type ( scNodeLabelInfoModel interface { Insert(ctx context.Context, data *ScNodeLabelInfo) (sql.Result, error) FindOne(ctx context.Context, id int64) (*ScNodeLabelInfo, error) Update(ctx context.Context, data *ScNodeLabelInfo) error Delete(ctx context.Context, id int64) error } defaultScNodeLabelInfoModel struct { sqlc.CachedConn table string } ScNodeLabelInfo struct { Id int64 `db:"id"` // id Label string `db:"label"` // 类型 NodeId int64 `db:"node_id"` // 节点id DeletedFlag int64 `db:"deleted_flag"` // 是否删除 CreatedBy sql.NullInt64 `db:"created_by"` // 创建人 CreatedTime time.Time `db:"created_time"` // 创建时间 UpdatedBy sql.NullInt64 `db:"updated_by"` // 更新人 UpdatedTime sql.NullTime `db:"updated_time"` // 更新时间 } ) func newScNodeLabelInfoModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) *defaultScNodeLabelInfoModel { return &defaultScNodeLabelInfoModel{ CachedConn: sqlc.NewConn(conn, c, opts...), table: "`sc_node_label_info`", } } func (m *defaultScNodeLabelInfoModel) withSession(session sqlx.Session) *defaultScNodeLabelInfoModel { return &defaultScNodeLabelInfoModel{ CachedConn: m.CachedConn.WithSession(session), table: "`sc_node_label_info`", } } func (m *defaultScNodeLabelInfoModel) Delete(ctx context.Context, id int64) error { pcmScNodeLabelInfoIdKey := fmt.Sprintf("%s%v", cachePcmScNodeLabelInfoIdPrefix, 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) }, pcmScNodeLabelInfoIdKey) return err } func (m *defaultScNodeLabelInfoModel) FindOne(ctx context.Context, id int64) (*ScNodeLabelInfo, error) { pcmScNodeLabelInfoIdKey := fmt.Sprintf("%s%v", cachePcmScNodeLabelInfoIdPrefix, id) var resp ScNodeLabelInfo err := m.QueryRowCtx(ctx, &resp, pcmScNodeLabelInfoIdKey, func(ctx context.Context, conn sqlx.SqlConn, v any) error { query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", scNodeLabelInfoRows, 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 *defaultScNodeLabelInfoModel) Insert(ctx context.Context, data *ScNodeLabelInfo) (sql.Result, error) { pcmScNodeLabelInfoIdKey := fmt.Sprintf("%s%v", cachePcmScNodeLabelInfoIdPrefix, 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, scNodeLabelInfoRowsExpectAutoSet) return conn.ExecCtx(ctx, query, data.Id, data.Label, data.NodeId, data.DeletedFlag, data.CreatedBy, data.CreatedTime, data.UpdatedBy, data.UpdatedTime) }, pcmScNodeLabelInfoIdKey) return ret, err } func (m *defaultScNodeLabelInfoModel) Update(ctx context.Context, data *ScNodeLabelInfo) error { pcmScNodeLabelInfoIdKey := fmt.Sprintf("%s%v", cachePcmScNodeLabelInfoIdPrefix, 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, scNodeLabelInfoRowsWithPlaceHolder) return conn.ExecCtx(ctx, query, data.Label, data.NodeId, data.DeletedFlag, data.CreatedBy, data.CreatedTime, data.UpdatedBy, data.UpdatedTime, data.Id) }, pcmScNodeLabelInfoIdKey) return err } func (m *defaultScNodeLabelInfoModel) formatPrimary(primary any) string { return fmt.Sprintf("%s%v", cachePcmScNodeLabelInfoIdPrefix, primary) } func (m *defaultScNodeLabelInfoModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary any) error { query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", scNodeLabelInfoRows, m.table) return conn.QueryRowCtx(ctx, v, query, primary) } func (m *defaultScNodeLabelInfoModel) tableName() string { return m.table }