dcDeviceRelationModel_gen.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // Code generated by goctl. DO NOT EDIT.
  2. package model
  3. import (
  4. "context"
  5. "database/sql"
  6. "fmt"
  7. "strings"
  8. "github.com/zeromicro/go-zero/core/stores/builder"
  9. "github.com/zeromicro/go-zero/core/stores/sqlc"
  10. "github.com/zeromicro/go-zero/core/stores/sqlx"
  11. "github.com/zeromicro/go-zero/core/stringx"
  12. )
  13. var (
  14. dcDeviceRelationFieldNames = builder.RawFieldNames(&DcDeviceRelation{})
  15. dcDeviceRelationRows = strings.Join(dcDeviceRelationFieldNames, ",")
  16. dcDeviceRelationRowsExpectAutoSet = strings.Join(stringx.Remove(dcDeviceRelationFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
  17. dcDeviceRelationRowsWithPlaceHolder = strings.Join(stringx.Remove(dcDeviceRelationFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
  18. )
  19. type (
  20. dcDeviceRelationModel interface {
  21. Insert(ctx context.Context, data *DcDeviceRelation) (sql.Result, error)
  22. FindOne(ctx context.Context, id int64) (*DcDeviceRelation, error)
  23. FindOneByProjectIdDeviceCode(ctx context.Context, projectId int64, deviceCode string) (*DcDeviceRelation, error)
  24. Update(ctx context.Context, data *DcDeviceRelation) error
  25. Delete(ctx context.Context, id int64) error
  26. }
  27. defaultDcDeviceRelationModel struct {
  28. conn sqlx.SqlConn
  29. table string
  30. }
  31. DcDeviceRelation struct {
  32. Id int64 `db:"id"`
  33. ProjectId int64 `db:"project_id"`
  34. DeviceCode string `db:"device_code"`
  35. Chest string `db:"chest"` // 与之相关的 chest 设备
  36. Pump string `db:"pump"` // 与之相关的 pump 设备
  37. Value string `db:"value"` // 与之相关的 value 设备
  38. }
  39. )
  40. func newDcDeviceRelationModel(conn sqlx.SqlConn) *defaultDcDeviceRelationModel {
  41. return &defaultDcDeviceRelationModel{
  42. conn: conn,
  43. table: "`dc_device_relation`",
  44. }
  45. }
  46. func (m *defaultDcDeviceRelationModel) withSession(session sqlx.Session) *defaultDcDeviceRelationModel {
  47. return &defaultDcDeviceRelationModel{
  48. conn: sqlx.NewSqlConnFromSession(session),
  49. table: "`dc_device_relation`",
  50. }
  51. }
  52. func (m *defaultDcDeviceRelationModel) Delete(ctx context.Context, id int64) error {
  53. query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
  54. _, err := m.conn.ExecCtx(ctx, query, id)
  55. return err
  56. }
  57. func (m *defaultDcDeviceRelationModel) FindOne(ctx context.Context, id int64) (*DcDeviceRelation, error) {
  58. query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", dcDeviceRelationRows, m.table)
  59. var resp DcDeviceRelation
  60. err := m.conn.QueryRowCtx(ctx, &resp, query, id)
  61. switch err {
  62. case nil:
  63. return &resp, nil
  64. case sqlc.ErrNotFound:
  65. return nil, ErrNotFound
  66. default:
  67. return nil, err
  68. }
  69. }
  70. func (m *defaultDcDeviceRelationModel) FindOneByProjectIdDeviceCode(ctx context.Context, projectId int64, deviceCode string) (*DcDeviceRelation, error) {
  71. var resp DcDeviceRelation
  72. query := fmt.Sprintf("select %s from %s where `project_id` = ? and `device_code` = ? limit 1", dcDeviceRelationRows, m.table)
  73. err := m.conn.QueryRowCtx(ctx, &resp, query, projectId, deviceCode)
  74. switch err {
  75. case nil:
  76. return &resp, nil
  77. case sqlc.ErrNotFound:
  78. return nil, ErrNotFound
  79. default:
  80. return nil, err
  81. }
  82. }
  83. func (m *defaultDcDeviceRelationModel) Insert(ctx context.Context, data *DcDeviceRelation) (sql.Result, error) {
  84. query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?)", m.table, dcDeviceRelationRowsExpectAutoSet)
  85. ret, err := m.conn.ExecCtx(ctx, query, data.ProjectId, data.DeviceCode, data.Chest, data.Pump, data.Value)
  86. return ret, err
  87. }
  88. func (m *defaultDcDeviceRelationModel) Update(ctx context.Context, newData *DcDeviceRelation) error {
  89. query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, dcDeviceRelationRowsWithPlaceHolder)
  90. _, err := m.conn.ExecCtx(ctx, query, newData.ProjectId, newData.DeviceCode, newData.Chest, newData.Pump, newData.Value, newData.Id)
  91. return err
  92. }
  93. func (m *defaultDcDeviceRelationModel) tableName() string {
  94. return m.table
  95. }