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.

dictmodel_gen.go 4.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // Code generated by goctl. DO NOT EDIT.
  2. package models
  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/cache"
  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. dictFieldNames = builder.RawFieldNames(&Dict{})
  16. dictRows = strings.Join(dictFieldNames, ",")
  17. dictRowsExpectAutoSet = strings.Join(stringx.Remove(dictFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
  18. dictRowsWithPlaceHolder = strings.Join(stringx.Remove(dictFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
  19. cachePcmDictIdPrefix = "cache:pcm:dict:id:"
  20. )
  21. type (
  22. dictModel interface {
  23. Insert(ctx context.Context, data *Dict) (sql.Result, error)
  24. FindOne(ctx context.Context, id int64) (*Dict, error)
  25. Update(ctx context.Context, data *Dict) error
  26. Delete(ctx context.Context, id int64) error
  27. }
  28. defaultDictModel struct {
  29. sqlc.CachedConn
  30. table string
  31. }
  32. Dict struct {
  33. Id int64 `db:"id"` // id
  34. DictName string `db:"dict_name"` // 字典名称
  35. DictCode string `db:"dict_code"` // 字典编号
  36. DictValue string `db:"dict_value"` // 字典值
  37. Source string `db:"source"` // 来源
  38. Description sql.NullString `db:"description"` // 描述
  39. CreatedBy sql.NullInt64 `db:"created_by"` // 创建人
  40. CreatedTime sql.NullTime `db:"created_time"` // 创建时间
  41. UpdatedBy sql.NullInt64 `db:"updated_by"` // 更新人
  42. UpdatedTime sql.NullTime `db:"updated_time"` // 更新时间
  43. DeletedFlag int64 `db:"deleted_flag"` // 是否删除(0-否,1-是)
  44. }
  45. )
  46. func newDictModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultDictModel {
  47. return &defaultDictModel{
  48. CachedConn: sqlc.NewConn(conn, c),
  49. table: "`dict`",
  50. }
  51. }
  52. func (m *defaultDictModel) Delete(ctx context.Context, id int64) error {
  53. pcmDictIdKey := fmt.Sprintf("%s%v", cachePcmDictIdPrefix, id)
  54. _, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
  55. query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
  56. return conn.ExecCtx(ctx, query, id)
  57. }, pcmDictIdKey)
  58. return err
  59. }
  60. func (m *defaultDictModel) FindOne(ctx context.Context, id int64) (*Dict, error) {
  61. pcmDictIdKey := fmt.Sprintf("%s%v", cachePcmDictIdPrefix, id)
  62. var resp Dict
  63. err := m.QueryRowCtx(ctx, &resp, pcmDictIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
  64. query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", dictRows, m.table)
  65. return conn.QueryRowCtx(ctx, v, query, id)
  66. })
  67. switch err {
  68. case nil:
  69. return &resp, nil
  70. case sqlc.ErrNotFound:
  71. return nil, ErrNotFound
  72. default:
  73. return nil, err
  74. }
  75. }
  76. func (m *defaultDictModel) Insert(ctx context.Context, data *Dict) (sql.Result, error) {
  77. pcmDictIdKey := fmt.Sprintf("%s%v", cachePcmDictIdPrefix, data.Id)
  78. ret, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
  79. query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, dictRowsExpectAutoSet)
  80. return conn.ExecCtx(ctx, query, data.DictName, data.DictCode, data.DictValue, data.Source, data.Description, data.CreatedBy, data.CreatedTime, data.UpdatedBy, data.UpdatedTime, data.DeletedFlag)
  81. }, pcmDictIdKey)
  82. return ret, err
  83. }
  84. func (m *defaultDictModel) Update(ctx context.Context, data *Dict) error {
  85. pcmDictIdKey := fmt.Sprintf("%s%v", cachePcmDictIdPrefix, data.Id)
  86. _, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
  87. query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, dictRowsWithPlaceHolder)
  88. return conn.ExecCtx(ctx, query, data.DictName, data.DictCode, data.DictValue, data.Source, data.Description, data.CreatedBy, data.CreatedTime, data.UpdatedBy, data.UpdatedTime, data.DeletedFlag, data.Id)
  89. }, pcmDictIdKey)
  90. return err
  91. }
  92. func (m *defaultDictModel) formatPrimary(primary interface{}) string {
  93. return fmt.Sprintf("%s%v", cachePcmDictIdPrefix, primary)
  94. }
  95. func (m *defaultDictModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary interface{}) error {
  96. query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", dictRows, m.table)
  97. return conn.QueryRowCtx(ctx, v, query, primary)
  98. }
  99. func (m *defaultDictModel) tableName() string {
  100. return m.table
  101. }

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.