|
- // 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 (
- cloudFieldNames = builder.RawFieldNames(&Cloud{})
- cloudRows = strings.Join(cloudFieldNames, ",")
- cloudRowsExpectAutoSet = strings.Join(stringx.Remove(cloudFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
- cloudRowsWithPlaceHolder = strings.Join(stringx.Remove(cloudFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
- )
-
- type (
- cloudModel interface {
- Insert(ctx context.Context, data *Cloud) (sql.Result, error)
- FindOne(ctx context.Context, id int64) (*Cloud, error)
- FindOneByNamespaceNameServiceName(ctx context.Context, namespace sql.NullString, name sql.NullString, serviceName sql.NullString) (*Cloud, error)
- Update(ctx context.Context, data *Cloud) error
- Delete(ctx context.Context, id int64) error
- }
-
- defaultCloudModel struct {
- conn sqlx.SqlConn
- table string
- }
-
- Cloud struct {
- Id int64 `db:"id"` // id
- TaskId int64 `db:"task_id"` // 任务id
- ApiVersion string `db:"api_version"`
- Name string `db:"name"` // 名称
- Namespace string `db:"namespace"` // 命名空间
- Kind string `db:"kind"` // 种类
- Status string `db:"status"` // 状态
- StartTime string `db:"start_time"` // 开始时间
- RunningTime int64 `db:"running_time"` // 运行时长
- 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-是)
- ServiceName string `db:"service_name"`
- YamlString string `db:"yaml_string"`
- Result string `db:"result"`
- }
- )
-
- func newCloudModel(conn sqlx.SqlConn) *defaultCloudModel {
- return &defaultCloudModel{
- conn: conn,
- table: "`cloud`",
- }
- }
-
- func (m *defaultCloudModel) 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 *defaultCloudModel) FindOne(ctx context.Context, id int64) (*Cloud, error) {
- query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", cloudRows, m.table)
- var resp Cloud
- 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 *defaultCloudModel) FindOneByNamespaceNameServiceName(ctx context.Context, namespace sql.NullString, name sql.NullString, serviceName sql.NullString) (*Cloud, error) {
- var resp Cloud
- query := fmt.Sprintf("select %s from %s where `namespace` = ? and `name` = ? and `service_name` = ? limit 1", cloudRows, m.table)
- err := m.conn.QueryRowCtx(ctx, &resp, query, namespace, name, serviceName)
- switch err {
- case nil:
- return &resp, nil
- case sqlc.ErrNotFound:
- return nil, ErrNotFound
- default:
- return nil, err
- }
- }
-
- func (m *defaultCloudModel) Insert(ctx context.Context, data *Cloud) (sql.Result, error) {
- query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, cloudRowsExpectAutoSet)
- ret, err := m.conn.ExecCtx(ctx, query, data.TaskId, data.ApiVersion, data.Name, data.Namespace, data.Kind, data.Status, data.StartTime, data.RunningTime, data.CreatedBy, data.CreatedTime, data.UpdatedBy, data.UpdatedTime, data.DeletedFlag, data.ServiceName, data.YamlString, data.Result)
- return ret, err
- }
-
- func (m *defaultCloudModel) Update(ctx context.Context, newData *Cloud) error {
- query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, cloudRowsWithPlaceHolder)
- _, err := m.conn.ExecCtx(ctx, query, newData.TaskId, newData.ApiVersion, newData.Name, newData.Namespace, newData.Kind, newData.Status, newData.StartTime, newData.RunningTime, newData.CreatedBy, newData.CreatedTime, newData.UpdatedBy, newData.UpdatedTime, newData.DeletedFlag, newData.ServiceName, newData.YamlString, newData.Result, newData.Id)
- return err
- }
-
- func (m *defaultCloudModel) tableName() string {
- return m.table
- }
|