dcAppInfoModel_gen.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // Code generated by goctl. DO NOT EDIT.
  2. package model
  3. import (
  4. "context"
  5. "database/sql"
  6. "fmt"
  7. "strings"
  8. "time"
  9. "github.com/zeromicro/go-zero/core/stores/builder"
  10. "github.com/zeromicro/go-zero/core/stores/sqlc"
  11. "github.com/zeromicro/go-zero/core/stores/sqlx"
  12. "github.com/zeromicro/go-zero/core/stringx"
  13. )
  14. var (
  15. dcAppInfoFieldNames = builder.RawFieldNames(&DcAppInfo{})
  16. dcAppInfoRows = strings.Join(dcAppInfoFieldNames, ",")
  17. dcAppInfoRowsExpectAutoSet = strings.Join(stringx.Remove(dcAppInfoFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
  18. dcAppInfoRowsWithPlaceHolder = strings.Join(stringx.Remove(dcAppInfoFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
  19. )
  20. type (
  21. dcAppInfoModel interface {
  22. Insert(ctx context.Context, data *DcAppInfo) (sql.Result, error)
  23. FindOne(ctx context.Context, id int64) (*DcAppInfo, error)
  24. FindOneByAppName(ctx context.Context, appName string) (*DcAppInfo, error)
  25. Update(ctx context.Context, data *DcAppInfo) error
  26. Delete(ctx context.Context, id int64) error
  27. }
  28. defaultDcAppInfoModel struct {
  29. conn sqlx.SqlConn
  30. table string
  31. }
  32. DcAppInfo struct {
  33. Id int64 `db:"id"`
  34. AppName string `db:"app_name"` // 应用名称
  35. ProjectId int64 `db:"project_id"` // 限定服务的project_id
  36. Secret string `db:"secret"` // 数据签名的secret
  37. Status int64 `db:"status"` // 状态 0: 正常 1: 禁用
  38. MTime time.Time `db:"m_time"` // 更新时间
  39. }
  40. )
  41. func newDcAppInfoModel(conn sqlx.SqlConn) *defaultDcAppInfoModel {
  42. return &defaultDcAppInfoModel{
  43. conn: conn,
  44. table: "`dc_app_info`",
  45. }
  46. }
  47. func (m *defaultDcAppInfoModel) withSession(session sqlx.Session) *defaultDcAppInfoModel {
  48. return &defaultDcAppInfoModel{
  49. conn: sqlx.NewSqlConnFromSession(session),
  50. table: "`dc_app_info`",
  51. }
  52. }
  53. func (m *defaultDcAppInfoModel) Delete(ctx context.Context, id int64) error {
  54. query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
  55. _, err := m.conn.ExecCtx(ctx, query, id)
  56. return err
  57. }
  58. func (m *defaultDcAppInfoModel) FindOne(ctx context.Context, id int64) (*DcAppInfo, error) {
  59. query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", dcAppInfoRows, m.table)
  60. var resp DcAppInfo
  61. err := m.conn.QueryRowCtx(ctx, &resp, query, id)
  62. switch err {
  63. case nil:
  64. return &resp, nil
  65. case sqlc.ErrNotFound:
  66. return nil, ErrNotFound
  67. default:
  68. return nil, err
  69. }
  70. }
  71. func (m *defaultDcAppInfoModel) FindOneByAppName(ctx context.Context, appName string) (*DcAppInfo, error) {
  72. var resp DcAppInfo
  73. query := fmt.Sprintf("select %s from %s where `app_name` = ? limit 1", dcAppInfoRows, m.table)
  74. err := m.conn.QueryRowCtx(ctx, &resp, query, appName)
  75. switch err {
  76. case nil:
  77. return &resp, nil
  78. case sqlc.ErrNotFound:
  79. return nil, ErrNotFound
  80. default:
  81. return nil, err
  82. }
  83. }
  84. func (m *defaultDcAppInfoModel) Insert(ctx context.Context, data *DcAppInfo) (sql.Result, error) {
  85. query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?)", m.table, dcAppInfoRowsExpectAutoSet)
  86. ret, err := m.conn.ExecCtx(ctx, query, data.AppName, data.ProjectId, data.Secret, data.Status, data.MTime)
  87. return ret, err
  88. }
  89. func (m *defaultDcAppInfoModel) Update(ctx context.Context, newData *DcAppInfo) error {
  90. query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, dcAppInfoRowsWithPlaceHolder)
  91. _, err := m.conn.ExecCtx(ctx, query, newData.AppName, newData.ProjectId, newData.Secret, newData.Status, newData.MTime, newData.Id)
  92. return err
  93. }
  94. func (m *defaultDcAppInfoModel) tableName() string {
  95. return m.table
  96. }