gdb链式操作使用方式简单灵活,是GoFrame框架官方推荐的数据库操作方式。链式操作可以通过数据库对象的db.Table/db.Model方法或者事务对象的tx.Table/tx.Model方法,基于指定的数据表返回一个链式操作对象*Model,该对象可以执行以下方法。

    当前方法列表可能滞后于源代码,详细的方法列表请参考接口文档: https://godoc.org/github.com/gogf/gf/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. // With关联查询
    41. func (m *Model) With(object interface{}) *Model
    42. func (m *Model) WithAll() *Model
    43. // 条件查询方法
    44. func (m *Model) Where(where interface{}, args...interface{}) *Model
    45. func (m *Model) WherePri(where interface{}, args ...interface{}) *Model
    46. func (m *Model) WhereBetween(column string, min, max interface{}) *Model
    47. func (m *Model) WhereLike(column string, like interface{}) *Model
    48. func (m *Model) WhereIn(column string, in interface{}) *Model
    49. func (m *Model) WhereNull(columns ...string) *Model
    50. func (m *Model) WhereNotBetween(column string, min, max interface{}) *Model
    51. func (m *Model) WhereNotLike(column string, like interface{}) *Model
    52. func (m *Model) WhereNotIn(column string, in interface{}) *Model
    53. func (m *Model) WhereNotNull(columns ...string) *Model
    54. func (m *Model) WhereOr(where interface{}, args ...interface{}) *Model
    55. func (m *Model) WhereOrBetween(column string, min, max interface{}) *Model
    56. func (m *Model) WhereOrLike(column string, like interface{}) *Model
    57. func (m *Model) WhereOrIn(column string, in interface{}) *Model
    58. func (m *Model) WhereOrNull(columns ...string) *Model
    59. func (m *Model) WhereOrNotBetween(column string, min, max interface{}) *Model
    60. func (m *Model) WhereOrNotLike(column string, like interface{}) *Model
    61. func (m *Model) WhereOrNotIn(column string, in interface{}) *Model
    62. func (m *Model) WhereOrNotNull(columns ...string) *Model
    63. // 分组排序方法
    64. func (m *Model) Group(group string) *Model
    65. func (m *Model) Order(order string) *Model
    66. func (m *Model) OrderAsc(column string) *Model
    67. func (m *Model) OrderDesc(column string) *Model
    68. func (m *Model) OrderRandom() *Model
    69. // 条件过滤方法
    70. func (m *Model) Fields(fields string) *Model
    71. func (m *Model) FieldsEx(fields string) *Model
    72. func (m *Model) Data(data...interface{}) *Model
    73. func (m *Model) Batch(batch int) *Model
    74. func (m *Model) Filter() *Model
    75. func (m *Model) Safe(safe...bool) *Model
    76. func (m *Model) Having(having interface{}, args ...interface{}) *Model
    77. func (m *Model) Offset(offset int) *Model
    78. func (m *Model) Limit(start int, limit int) *Model
    79. func (m *Model) OmitEmpty() *Model
    80. func (m *Model) Page(page, limit int) (*Model)
    81. func (m *Model) Distinct() *Model
    82. // 数据库/事务切换
    83. func (m *Model) DB(db DB) *Model
    84. func (m *Model) TX(tx *TX) *Model
    85. // 主从自定义切换
    86. func (m *Model) Master() *Model
    87. func (m *Model) Slave() *Model
    88. // 数据互斥锁操作
    89. func (m *Model) LockUpdate() *Model
    90. func (m *Model) LockShared() *Model
    91. // 常用工具方法
    92. func (m *Model) Ctx(ctx context.Context) *Model
    93. func (m *Model) Clone() *Model
    94. func (m *Model) Cache(duration time.Duration, name ...string) *Model
    95. func (m *Model) As(as string) *Model
    96. func (m *Model) Chunk(limit int, callback func(result Result, err error) bool)
    97. func (m *Model) Schema(schema string) *Model
    98. func (m *Model) Option(option int) *Model
    99. func (m *Model) Args(args ...interface{}) *Model
    100. func (m *Model) Unscoped() *Model
    101. func (m *Model) HasField(field string) (bool, error)
    102. func (m *Model) GetFieldsStr(prefix ...string) string
    103. func (m *Model) GetFieldsExStr(fields string, prefix ...string) string