business_checker_model.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. // ==========================================================================
  2. // This is auto-generated by gf cli tool. You may not really want to edit it.
  3. // ==========================================================================
  4. package wf_business_checker
  5. import (
  6. "database/sql"
  7. "github.com/gogf/gf/database/gdb"
  8. "github.com/gogf/gf/frame/g"
  9. "github.com/gogf/gf/frame/gmvc"
  10. "time"
  11. )
  12. // arModel is a active record design model for table wf_business_checker operations.
  13. type arModel struct {
  14. gmvc.M
  15. }
  16. var (
  17. // Table is the table name of wf_business_checker.
  18. Table = "wf_business_checker"
  19. // Model is the model object of wf_business_checker.
  20. Model = &arModel{g.DB("default").Table(Table).Safe()}
  21. // Columns defines and stores column names for table wf_business_checker.
  22. Columns = struct {
  23. Id string // 主键
  24. FromTable string // 业务表名
  25. FromId string // 业务id
  26. UserId string // 用户id
  27. DepartmentId string // 部门id
  28. }{
  29. Id: "id",
  30. FromTable: "from_table",
  31. FromId: "from_id",
  32. UserId: "user_id",
  33. DepartmentId: "department_id",
  34. }
  35. )
  36. // As sets an alias name for current table.
  37. func (m *arModel) As(as string) *arModel {
  38. return &arModel{m.M.As(as)}
  39. }
  40. // TX sets the transaction for current operation.
  41. func (m *arModel) TX(tx *gdb.TX) *arModel {
  42. return &arModel{m.M.TX(tx)}
  43. }
  44. // Master marks the following operation on master node.
  45. func (m *arModel) Master() *arModel {
  46. return &arModel{m.M.Master()}
  47. }
  48. // Slave marks the following operation on slave node.
  49. // Note that it makes sense only if there's any slave node configured.
  50. func (m *arModel) Slave() *arModel {
  51. return &arModel{m.M.Slave()}
  52. }
  53. // LeftJoin does "LEFT JOIN ... ON ..." statement on the model.
  54. // The parameter <table> can be joined table and its joined condition,
  55. // and also with its alias name, like:
  56. // Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid")
  57. // Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid")
  58. func (m *arModel) LeftJoin(table ...string) *arModel {
  59. return &arModel{m.M.LeftJoin(table...)}
  60. }
  61. // RightJoin does "RIGHT JOIN ... ON ..." statement on the model.
  62. // The parameter <table> can be joined table and its joined condition,
  63. // and also with its alias name, like:
  64. // Table("user").RightJoin("user_detail", "user_detail.uid=user.uid")
  65. // Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid")
  66. func (m *arModel) RightJoin(table ...string) *arModel {
  67. return &arModel{m.M.RightJoin(table...)}
  68. }
  69. // InnerJoin does "INNER JOIN ... ON ..." statement on the model.
  70. // The parameter <table> can be joined table and its joined condition,
  71. // and also with its alias name, like:
  72. // Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid")
  73. // Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid")
  74. func (m *arModel) InnerJoin(table ...string) *arModel {
  75. return &arModel{m.M.InnerJoin(table...)}
  76. }
  77. // Fields sets the operation fields of the model, multiple fields joined using char ','.
  78. func (m *arModel) Fields(fields ...string) *arModel {
  79. return &arModel{m.M.Fields(fields)}
  80. }
  81. // FieldsEx sets the excluded operation fields of the model, multiple fields joined using char ','.
  82. func (m *arModel) FieldsEx(fields ...string) *arModel {
  83. return &arModel{m.M.FieldsEx(fields)}
  84. }
  85. // Option sets the extra operation option for the model.
  86. func (m *arModel) Option(option int) *arModel {
  87. return &arModel{m.M.Option(option)}
  88. }
  89. // OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers
  90. // the data and where attributes for empty values.
  91. func (m *arModel) OmitEmpty() *arModel {
  92. return &arModel{m.M.OmitEmpty()}
  93. }
  94. // Filter marks filtering the fields which does not exist in the fields of the operated table.
  95. func (m *arModel) Filter() *arModel {
  96. return &arModel{m.M.Filter()}
  97. }
  98. // Where sets the condition statement for the model. The parameter <where> can be type of
  99. // string/map/gmap/slice/struct/*struct, etc. Note that, if it's called more than one times,
  100. // multiple conditions will be joined into where statement using "AND".
  101. // Eg:
  102. // Where("uid=10000")
  103. // Where("uid", 10000)
  104. // Where("money>? AND name like ?", 99999, "vip_%")
  105. // Where("uid", 1).Where("name", "john")
  106. // Where("status IN (?)", g.Slice{1,2,3})
  107. // Where("age IN(?,?)", 18, 50)
  108. // Where(User{ Id : 1, UserName : "john"})
  109. func (m *arModel) Where(where interface{}, args ...interface{}) *arModel {
  110. return &arModel{m.M.Where(where, args...)}
  111. }
  112. // WherePri does the same logic as Model.Where except that if the parameter <where>
  113. // is a single condition like int/string/float/slice, it treats the condition as the primary
  114. // key value. That is, if primary key is "id" and given <where> parameter as "123", the
  115. // WherePri function treats the condition as "id=123", but Model.Where treats the condition
  116. // as string "123".
  117. func (m *arModel) WherePri(where interface{}, args ...interface{}) *arModel {
  118. return &arModel{m.M.WherePri(where, args...)}
  119. }
  120. // And adds "AND" condition to the where statement.
  121. func (m *arModel) And(where interface{}, args ...interface{}) *arModel {
  122. return &arModel{m.M.And(where, args...)}
  123. }
  124. // Or adds "OR" condition to the where statement.
  125. func (m *arModel) Or(where interface{}, args ...interface{}) *arModel {
  126. return &arModel{m.M.Or(where, args...)}
  127. }
  128. // Group sets the "GROUP BY" statement for the model.
  129. func (m *arModel) Group(groupBy string) *arModel {
  130. return &arModel{m.M.Group(groupBy)}
  131. }
  132. // Order sets the "ORDER BY" statement for the model.
  133. func (m *arModel) Order(orderBy ...string) *arModel {
  134. return &arModel{m.M.Order(orderBy...)}
  135. }
  136. // Limit sets the "LIMIT" statement for the model.
  137. // The parameter <limit> can be either one or two number, if passed two number is passed,
  138. // it then sets "LIMIT limit[0],limit[1]" statement for the model, or else it sets "LIMIT limit[0]"
  139. // statement.
  140. func (m *arModel) Limit(limit ...int) *arModel {
  141. return &arModel{m.M.Limit(limit...)}
  142. }
  143. // Offset sets the "OFFSET" statement for the model.
  144. // It only makes sense for some databases like SQLServer, PostgreSQL, etc.
  145. func (m *arModel) Offset(offset int) *arModel {
  146. return &arModel{m.M.Offset(offset)}
  147. }
  148. // Page sets the paging number for the model.
  149. // The parameter <page> is started from 1 for paging.
  150. // Note that, it differs that the Limit function start from 0 for "LIMIT" statement.
  151. func (m *arModel) Page(page, limit int) *arModel {
  152. return &arModel{m.M.Page(page, limit)}
  153. }
  154. // Batch sets the batch operation number for the model.
  155. func (m *arModel) Batch(batch int) *arModel {
  156. return &arModel{m.M.Batch(batch)}
  157. }
  158. // Cache sets the cache feature for the model. It caches the result of the sql, which means
  159. // if there's another same sql request, it just reads and returns the result from cache, it
  160. // but not committed and executed into the database.
  161. //
  162. // If the parameter <duration> < 0, which means it clear the cache with given <name>.
  163. // If the parameter <duration> = 0, which means it never expires.
  164. // If the parameter <duration> > 0, which means it expires after <duration>.
  165. //
  166. // The optional parameter <name> is used to bind a name to the cache, which means you can later
  167. // control the cache like changing the <duration> or clearing the cache with specified <name>.
  168. //
  169. // Note that, the cache feature is disabled if the model is operating on a transaction.
  170. func (m *arModel) Cache(duration time.Duration, name ...string) *arModel {
  171. return &arModel{m.M.Cache(duration, name...)}
  172. }
  173. // Data sets the operation data for the model.
  174. // The parameter <data> can be type of string/map/gmap/slice/struct/*struct, etc.
  175. // Eg:
  176. // Data("uid=10000")
  177. // Data("uid", 10000)
  178. // Data(g.Map{"uid": 10000, "name":"john"})
  179. // Data(g.Slice{g.Map{"uid": 10000, "name":"john"}, g.Map{"uid": 20000, "name":"smith"})
  180. func (m *arModel) Data(data ...interface{}) *arModel {
  181. return &arModel{m.M.Data(data...)}
  182. }
  183. // All does "SELECT FROM ..." statement for the model.
  184. // It retrieves the records from table and returns the result as []*Entity.
  185. // It returns nil if there's no record retrieved with the given conditions from table.
  186. //
  187. // The optional parameter <where> is the same as the parameter of Model.Where function,
  188. // see Model.Where.
  189. func (m *arModel) All(where ...interface{}) ([]*Entity, error) {
  190. all, err := m.M.All(where...)
  191. if err != nil {
  192. return nil, err
  193. }
  194. var entities []*Entity
  195. if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
  196. return nil, err
  197. }
  198. return entities, nil
  199. }
  200. // One retrieves one record from table and returns the result as *Entity.
  201. // It returns nil if there's no record retrieved with the given conditions from table.
  202. //
  203. // The optional parameter <where> is the same as the parameter of Model.Where function,
  204. // see Model.Where.
  205. func (m *arModel) One(where ...interface{}) (*Entity, error) {
  206. one, err := m.M.One(where...)
  207. if err != nil {
  208. return nil, err
  209. }
  210. var entity *Entity
  211. if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
  212. return nil, err
  213. }
  214. return entity, nil
  215. }
  216. // FindOne retrieves and returns a single Record by Model.WherePri and Model.One.
  217. // Also see Model.WherePri and Model.One.
  218. func (m *arModel) FindOne(where ...interface{}) (*Entity, error) {
  219. one, err := m.M.FindOne(where...)
  220. if err != nil {
  221. return nil, err
  222. }
  223. var entity *Entity
  224. if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
  225. return nil, err
  226. }
  227. return entity, nil
  228. }
  229. // FindAll retrieves and returns Result by by Model.WherePri and Model.All.
  230. // Also see Model.WherePri and Model.All.
  231. func (m *arModel) FindAll(where ...interface{}) ([]*Entity, error) {
  232. all, err := m.M.FindAll(where...)
  233. if err != nil {
  234. return nil, err
  235. }
  236. var entities []*Entity
  237. if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
  238. return nil, err
  239. }
  240. return entities, nil
  241. }
  242. // Chunk iterates the table with given size and callback function.
  243. func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error) bool) {
  244. m.M.Chunk(limit, func(result gdb.Result, err error) bool {
  245. var entities []*Entity
  246. err = result.Structs(&entities)
  247. if err == sql.ErrNoRows {
  248. return false
  249. }
  250. return callback(entities, err)
  251. })
  252. }
  253. // LockUpdate sets the lock for update for current operation.
  254. func (m *arModel) LockUpdate() *arModel {
  255. return &arModel{m.M.LockUpdate()}
  256. }
  257. // LockShared sets the lock in share mode for current operation.
  258. func (m *arModel) LockShared() *arModel {
  259. return &arModel{m.M.LockShared()}
  260. }
  261. // Unscoped enables/disables the soft deleting feature.
  262. func (m *arModel) Unscoped() *arModel {
  263. return &arModel{m.M.Unscoped()}
  264. }