// 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 ( hpcFieldNames = builder.RawFieldNames(&Hpc{}) hpcRows = strings.Join(hpcFieldNames, ",") hpcRowsExpectAutoSet = strings.Join(stringx.Remove(hpcFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",") hpcRowsWithPlaceHolder = strings.Join(stringx.Remove(hpcFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?" ) type ( hpcModel interface { Insert(ctx context.Context, data *Hpc) (sql.Result, error) FindOne(ctx context.Context, id int64) (*Hpc, error) FindOneByServiceNameName(ctx context.Context, serviceName sql.NullString, name sql.NullString) (*Hpc, error) Update(ctx context.Context, data *Hpc) error Delete(ctx context.Context, id int64) error } defaultHpcModel struct { conn sqlx.SqlConn table string } Hpc struct { Id int64 `db:"id"` // id TaskId int64 `db:"task_id"` // 任务id JobId string `db:"job_id"` // 作业id ServiceName string `db:"service_name"` // 服务名称 Name string `db:"name"` // 名称 Status string `db:"status"` // 状态 StartTime string `db:"start_time"` // 开始时间 RunningTime int64 `db:"running_time"` // 运行时间 CardCount int64 `db:"card_count"` // 卡数 CreatedBy int64 `db:"created_by"` // 创建人 CreatedTime sql.NullTime `db:"created_time"` // 创建时间 UpdatedBy int64 `db:"updated_by"` // 更新人 UpdatedTime sql.NullTime `db:"updated_time"` // 更新时间 DeletedFlag int64 `db:"deleted_flag"` // 是否删除(0-否,1-是) WorkDir string `db:"work_dir"` WallTime string `db:"wall_time"` Result string `db:"result"` YamlString string `db:"yaml_string"` CmdScript string `db:"cmd_script"` derivedEs string `db:"derived_es"` cluster string `db:"cluster"` blockId string `db:"block_id"` allocNodes uint32 `db:"alloc_nodes"` allocCpu uint32 `db:"alloc_cpu"` version string `db:"version"` account string `db:"account"` exitCode uint32 `db:"exit_code"` assocId uint32 `db:"assoc_id"` } ) func newHpcModel(conn sqlx.SqlConn) *defaultHpcModel { return &defaultHpcModel{ conn: conn, table: "`hpc`", } } func (m *defaultHpcModel) 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 *defaultHpcModel) FindOne(ctx context.Context, id int64) (*Hpc, error) { query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", hpcRows, m.table) var resp Hpc 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 *defaultHpcModel) FindOneByServiceNameName(ctx context.Context, serviceName sql.NullString, name sql.NullString) (*Hpc, error) { var resp Hpc query := fmt.Sprintf("select %s from %s where `service_name` = ? and `name` = ? limit 1", hpcRows, m.table) err := m.conn.QueryRowCtx(ctx, &resp, query, serviceName, name) switch err { case nil: return &resp, nil case sqlc.ErrNotFound: return nil, ErrNotFound default: return nil, err } } func (m *defaultHpcModel) Insert(ctx context.Context, data *Hpc) (sql.Result, error) { query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, hpcRowsExpectAutoSet) ret, err := m.conn.ExecCtx(ctx, query, data.TaskId, data.JobId, data.ServiceName, data.Name, data.Status, data.StartTime, data.RunningTime, data.CardCount, data.CreatedBy, data.CreatedTime, data.UpdatedBy, data.UpdatedTime, data.DeletedFlag, data.WorkDir, data.WallTime, data.Result, data.YamlString) return ret, err } func (m *defaultHpcModel) Update(ctx context.Context, newData *Hpc) error { query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, hpcRowsWithPlaceHolder) _, err := m.conn.ExecCtx(ctx, query, newData.TaskId, newData.JobId, newData.ServiceName, newData.Name, newData.Status, newData.StartTime, newData.RunningTime, newData.CardCount, newData.CreatedBy, newData.CreatedTime, newData.UpdatedBy, newData.UpdatedTime, newData.DeletedFlag, newData.WorkDir, newData.WallTime, newData.Result, newData.YamlString, newData.Id) return err } func (m *defaultHpcModel) tableName() string { return m.table }