You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

tbaseresourcespecmodel_gen.go 4.3 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // Code generated by goctl. DO NOT EDIT.
  2. // versions:
  3. // goctl version: 1.8.1
  4. package models
  5. import (
  6. "context"
  7. "database/sql"
  8. "fmt"
  9. "gorm.io/gorm"
  10. "strings"
  11. "time"
  12. "github.com/zeromicro/go-zero/core/stores/builder"
  13. "github.com/zeromicro/go-zero/core/stores/sqlx"
  14. "github.com/zeromicro/go-zero/core/stringx"
  15. )
  16. var (
  17. tBaseResourceSpecFieldNames = builder.RawFieldNames(&TBaseResourceSpec{})
  18. tBaseResourceSpecRows = strings.Join(tBaseResourceSpecFieldNames, ",")
  19. tBaseResourceSpecRowsExpectAutoSet = strings.Join(stringx.Remove(tBaseResourceSpecFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
  20. tBaseResourceSpecRowsWithPlaceHolder = strings.Join(stringx.Remove(tBaseResourceSpecFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
  21. )
  22. type (
  23. tBaseResourceSpecModel interface {
  24. Insert(ctx context.Context, data *TBaseResourceSpec) (sql.Result, error)
  25. FindOne(ctx context.Context, id int64) (*TBaseResourceSpec, error)
  26. Update(ctx context.Context, data *TBaseResourceSpec) error
  27. Delete(ctx context.Context, id int64) error
  28. }
  29. defaultTBaseResourceSpecModel struct {
  30. conn sqlx.SqlConn
  31. table string
  32. }
  33. TBaseResourceSpec struct {
  34. Id int64 `db:"id" json:"id"` // 主键id
  35. ResourceSpecId int64 `db:"resource_spec_id" json:"resourceSpecId"` // 关联资源规格ID
  36. Type string `db:"type" json:"type"` // 类型名称
  37. Name string `db:"name" json:"name"` // 名称(如显存类型)
  38. TotalValue float64 `db:"total_value" json:"totalValue"` // 总量值
  39. TotalUnit string `db:"total_unit" json:"totalUnit"` // 总量值单位(GB/core等)
  40. AvailableValue float64 `db:"available_value" json:"availableValue"` // 可用值
  41. AvailableUnit string `db:"available_unit" json:"availableUnit"` // 可用值单位(GB/core等)
  42. UserId int64 `db:"user_id" json:"userId"` // 用户ID
  43. CreateTime time.Time `db:"create_time" json:"createTime"` // 创建时间
  44. UpdateTime time.Time `db:"update_time" json:"updateTime"` // 更新时间
  45. DeletedAt gorm.DeletedAt `db:"deleted_at" json:"-"` // 删除时间
  46. }
  47. )
  48. func newTBaseResourceSpecModel(conn sqlx.SqlConn) *defaultTBaseResourceSpecModel {
  49. return &defaultTBaseResourceSpecModel{
  50. conn: conn,
  51. table: "`t_base_resource_spec`",
  52. }
  53. }
  54. func (m *defaultTBaseResourceSpecModel) Delete(ctx context.Context, id int64) error {
  55. query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
  56. _, err := m.conn.ExecCtx(ctx, query, id)
  57. return err
  58. }
  59. func (m *defaultTBaseResourceSpecModel) FindOne(ctx context.Context, id int64) (*TBaseResourceSpec, error) {
  60. query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", tBaseResourceSpecRows, m.table)
  61. var resp TBaseResourceSpec
  62. err := m.conn.QueryRowCtx(ctx, &resp, query, id)
  63. switch err {
  64. case nil:
  65. return &resp, nil
  66. case sqlx.ErrNotFound:
  67. return nil, ErrNotFound
  68. default:
  69. return nil, err
  70. }
  71. }
  72. func (m *defaultTBaseResourceSpecModel) Insert(ctx context.Context, data *TBaseResourceSpec) (sql.Result, error) {
  73. query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, tBaseResourceSpecRowsExpectAutoSet)
  74. ret, err := m.conn.ExecCtx(ctx, query, data.ResourceSpecId, data.Type, data.Name, data.TotalValue, data.TotalUnit, data.AvailableValue, data.AvailableUnit, data.UserId, data.DeletedAt)
  75. return ret, err
  76. }
  77. func (m *defaultTBaseResourceSpecModel) Update(ctx context.Context, data *TBaseResourceSpec) error {
  78. query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, tBaseResourceSpecRowsWithPlaceHolder)
  79. _, err := m.conn.ExecCtx(ctx, query, data.ResourceSpecId, data.Type, data.Name, data.TotalValue, data.TotalUnit, data.AvailableValue, data.AvailableUnit, data.UserId, data.DeletedAt, data.Id)
  80. return err
  81. }
  82. func (m *defaultTBaseResourceSpecModel) tableName() string {
  83. return m.table
  84. }

PCM is positioned as Software stack over Cloud, aiming to build the standards and ecology of heterogeneous cloud collaboration for JCC in a non intrusive and autonomous peer-to-peer manner.