|
- // Code generated by goctl. DO NOT EDIT.
-
- package models
-
- 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 (
- taskVmFieldNames = builder.RawFieldNames(&TaskVm{})
- taskVmRows = strings.Join(taskVmFieldNames, ",")
- taskVmRowsExpectAutoSet = strings.Join(stringx.Remove(taskVmFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
- taskVmRowsWithPlaceHolder = strings.Join(stringx.Remove(taskVmFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
- )
-
- type (
- taskVmModel interface {
- Insert(ctx context.Context, data *TaskVm) (sql.Result, error)
- FindOne(ctx context.Context, id int64) (*TaskVm, error)
- Update(ctx context.Context, data *TaskVm) error
- Delete(ctx context.Context, id int64) error
- }
-
- defaultTaskVmModel struct {
- conn sqlx.SqlConn
- table string
- }
-
- TaskVm struct {
- Id int64 `db:"id"` // id
- ParticipantId int64 `db:"participant_id"` // p端id
- TaskId int64 `db:"task_id"` // 任务id
- Name string `db:"name"` // 虚拟机名称
- AdapterId int64 `db:"adapter_id"` // 执行任务的适配器id
- ClusterId int64 `db:"cluster_id"` // 执行任务的集群id
- FlavorRef string `db:"flavor_ref"` // 规格索引
- ImageRef string `db:"image_ref"` // 镜像索引
- Status string `db:"status"` // 状态
- Platform string `db:"platform"` // 平台
- Description string `db:"description"` // 描述
- AvailabilityZone string `db:"availability_zone"`
- MinCount int64 `db:"min_count"` // 数量
- Uuid string `db:"uuid"` // 网络id
- StartTime string `db:"start_time"` // 开始时间
- RunningTime string `db:"running_time"` // 运行时间
- Result string `db:"result"` // 运行结果
- DeletedAt string `db:"deleted_at"` // 删除时间
- }
- )
-
- func newTaskVmModel(conn sqlx.SqlConn) *defaultTaskVmModel {
- return &defaultTaskVmModel{
- conn: conn,
- table: "`task_vm`",
- }
- }
-
- func (m *defaultTaskVmModel) withSession(session sqlx.Session) *defaultTaskVmModel {
- return &defaultTaskVmModel{
- conn: sqlx.NewSqlConnFromSession(session),
- table: "`task_vm`",
- }
- }
-
- func (m *defaultTaskVmModel) 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 *defaultTaskVmModel) FindOne(ctx context.Context, id int64) (*TaskVm, error) {
- query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", taskVmRows, m.table)
- var resp TaskVm
- 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 *defaultTaskVmModel) Insert(ctx context.Context, data *TaskVm) (sql.Result, error) {
- query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, taskVmRowsExpectAutoSet)
- ret, err := m.conn.ExecCtx(ctx, query, data.ParticipantId, data.TaskId, data.Name, data.AdapterId, data.ClusterId, data.FlavorRef, data.ImageRef, data.Status, data.Platform, data.Description, data.AvailabilityZone, data.MinCount, data.Uuid, data.StartTime, data.RunningTime, data.Result, data.DeletedAt)
- return ret, err
- }
-
- func (m *defaultTaskVmModel) Update(ctx context.Context, data *TaskVm) error {
- query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, taskVmRowsWithPlaceHolder)
- _, err := m.conn.ExecCtx(ctx, query, data.ParticipantId, data.TaskId, data.Name, data.AdapterId, data.ClusterId, data.FlavorRef, data.ImageRef, data.Status, data.Platform, data.Description, data.AvailabilityZone, data.MinCount, data.Uuid, data.StartTime, data.RunningTime, data.Result, data.DeletedAt, data.Id)
- return err
- }
-
- func (m *defaultTaskVmModel) tableName() string {
- return m.table
- }
|