基本介绍

gdb链式操作使用方式简单灵活,是GoFrame框架官方推荐的数据库操作方式。链式操作可以通过数据库对象的db.Model方法或者事务对象的tx.Model方法,基于指定的数据表返回一个链式操作对象*Model,该对象可以执行以下方法。当前方法列表可能滞后于源代码,详细的方法列表请参考接口文档: https://pkg.go.dev/github.com/gogf/gf/v2/database/gdb#Model

  1. // 写入/更新/删除基本操作
  2. func (m *Model) Insert(data ...interface{}) (result sql.Result, err error)
  3. func (m *Model) InsertAndGetId(data ...interface{}) (lastInsertId int64, err error)
  4. func (m *Model) InsertIgnore(data ...interface{}) (result sql.Result, err error)
  5. func (m *Model) Replace(data ...interface{}) (result sql.Result, err error)
  6. func (m *Model) Save(data ...interface{}) (result sql.Result, err error)
  7. func (m *Model) Update(dataAndWhere ...interface{}) (result sql.Result, err error)
  8. func (m *Model) Delete(where ...interface{}) (result sql.Result, err error)
  9. // 基本查询操作
  10. func (m *Model) All(where ...interface{} (Result, error)
  11. func (m *Model) One(where ...interface{}) (Record, error)
  12. func (m *Model) Array(fieldsAndWhere ...interface{}) ([]Value, error)
  13. func (m *Model) Value(fieldsAndWhere ...interface{}) (Value, error)
  14. func (m *Model) Count(where ...interface{}) (int, error)
  15. func (m *Model) CountColumn(column string) (int, error)
  16. // 常用基本统计
  17. func (m *Model) Min(column string) (float64, error)
  18. func (m *Model) Max(column string) (float64, error)
  19. func (m *Model) Avg(column string) (float64, error)
  20. func (m *Model) Sum(column string) (float64, error)
  21. // 字段自增/自减
  22. func (m *Model) Increment(column string, amount float64) (sql.Result, error)
  23. func (m *Model) Decrement(column string, amount float64) (sql.Result, error)
  24. // 主键查询操作
  25. func (m *Model) FindAll(where ...interface{}) (Result, error)
  26. func (m *Model) FindOne(where ...interface{}) (Record, error)
  27. func (m *Model) FindArray(fieldsAndWhere ...interface{}) (Value, error)
  28. func (m *Model) FindValue(fieldsAndWhere ...interface{}) (Value, error)
  29. func (m *Model) FindCount(where ...interface{}) (int, error)
  30. func (m *Model) FindScan(pointer interface{}, where ...interface{}) error
  31. // 查询转换操作
  32. func (m *Model) Struct(pointer interface{}) error
  33. func (m *Model) Structs(pointer interface{}) error
  34. func (m *Model) Scan(pointer interface{}) error
  35. func (m *Model) ScanList(listPointer interface{}, attributeName string, relation ...string) (err error)
  36. // 联表查询方法
  37. func (m *Model) LeftJoin(table ...string) *Model
  38. func (m *Model) RightJoin(table ...string) *Model
  39. func (m *Model) InnerJoin(table ...string) *Model
  40. // 联合查询
  41. func (m *Model) Union(unions ...*Model) *Model
  42. func (m *Model) UnionAll(unions ...*Model) *Model
  43. // With关联查询
  44. func (m *Model) With(object interface{}) *Model
  45. func (m *Model) WithAll() *Model
  46. // 条件查询方法
  47. func (m *Model) Where(where interface{}, args...interface{}) *Model
  48. func (m *Model) WherePri(where interface{}, args ...interface{}) *Model
  49. func (m *Model) WhereBetween(column string, min, max interface{}) *Model
  50. func (m *Model) WhereLike(column string, like interface{}) *Model
  51. func (m *Model) WhereIn(column string, in interface{}) *Model
  52. func (m *Model) WhereNull(columns ...string) *Model
  53. func (m *Model) WhereLT(column string, value interface{}) *Model
  54. func (m *Model) WhereLTE(column string, value interface{}) *Model
  55. func (m *Model) WhereGT(column string, value interface{}) *Model
  56. func (m *Model) WhereGTE(column string, value interface{}) *Model
  57. func (m *Model) WhereNotBetween(column string, min, max interface{}) *Model
  58. func (m *Model) WhereNotLike(column string, like interface{}) *Model
  59. func (m *Model) WhereNotIn(column string, in interface{}) *Model
  60. func (m *Model) WhereNotNull(columns ...string) *Model
  61. func (m *Model) WhereOr(where interface{}, args ...interface{}) *Model
  62. func (m *Model) WhereOrBetween(column string, min, max interface{}) *Model
  63. func (m *Model) WhereOrLike(column string, like interface{}) *Model
  64. func (m *Model) WhereOrIn(column string, in interface{}) *Model
  65. func (m *Model) WhereOrNull(columns ...string) *Model
  66. func (m *Model) WhereOrLT(column string, value interface{}) *Model
  67. func (m *Model) WhereOrLTE(column string, value interface{}) *Model
  68. func (m *Model) WhereOrGT(column string, value interface{}) *Model
  69. func (m *Model) WhereOrGTE(column string, value interface{}) *Model
  70. func (m *Model) WhereOrNotBetween(column string, min, max interface{}) *Model
  71. func (m *Model) WhereOrNotLike(column string, like interface{}) *Model
  72. func (m *Model) WhereOrNotIn(column string, in interface{}) *Model
  73. func (m *Model) WhereOrNotNull(columns ...string) *Model
  74. // 分组排序方法
  75. func (m *Model) Group(group string) *Model
  76. func (m *Model) Order(order string) *Model
  77. func (m *Model) OrderAsc(column string) *Model
  78. func (m *Model) OrderDesc(column string) *Model
  79. func (m *Model) OrderRandom() *Model
  80. // 条件过滤方法
  81. func (m *Model) Fields(fields string) *Model
  82. func (m *Model) FieldsEx(fields string) *Model
  83. func (m *Model) Data(data...interface{}) *Model
  84. func (m *Model) Batch(batch int) *Model
  85. func (m *Model) Filter() *Model
  86. func (m *Model) Safe(safe...bool) *Model
  87. func (m *Model) Having(having interface{}, args ...interface{}) *Model
  88. func (m *Model) Offset(offset int) *Model
  89. func (m *Model) Limit(start int, limit int) *Model
  90. func (m *Model) OmitEmpty() *Model
  91. func (m *Model) Page(page, limit int) (*Model)
  92. func (m *Model) Distinct() *Model
  93. // 数据库/事务切换
  94. func (m *Model) DB(db DB) *Model
  95. func (m *Model) TX(tx *TX) *Model
  96. // 主从自定义切换
  97. func (m *Model) Master() *Model
  98. func (m *Model) Slave() *Model
  99. // 数据互斥锁操作
  100. func (m *Model) LockUpdate() *Model
  101. func (m *Model) LockShared() *Model
  102. // 常用工具方法
  103. func (m *Model) Ctx(ctx context.Context) *Model
  104. func (m *Model) Clone() *Model
  105. func (m *Model) Cache(duration time.Duration, name ...string) *Model
  106. func (m *Model) As(as string) *Model
  107. func (m *Model) Chunk(limit int, callback func(result Result, err error) bool)
  108. func (m *Model) Schema(schema string) *Model
  109. func (m *Model) Option(option int) *Model
  110. func (m *Model) Args(args ...interface{}) *Model
  111. func (m *Model) Unscoped() *Model
  112. func (m *Model) HasField(field string) (bool, error)
  113. func (m *Model) GetFieldsStr(prefix ...string) string
  114. func (m *Model) GetFieldsExStr(fields string, prefix ...string) string

相关文档