model_fields_model.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. // ==========================================================================
  2. // This is auto-generated by gf cli tool. You may not really want to edit it.
  3. // ==========================================================================
  4. package model_fields
  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 model_fields operations.
  13. type arModel struct {
  14. gmvc.M
  15. }
  16. var (
  17. // Table is the table name of model_fields.
  18. Table = "model_fields"
  19. // Model is the model object of model_fields.
  20. Model = &arModel{g.DB("default").Table(Table).Safe()}
  21. // Columns defines and stores column names for table model_fields.
  22. Columns = struct {
  23. FieldId string // 模型字段ID
  24. ModelId string // 模型ID
  25. FieldName string // 字段名称
  26. FieldTitle string // 字段标题
  27. FieldType string // 字段类型
  28. FieldLength string // 字段长度
  29. FieldDefault string // 字段默认值
  30. FieldData string // 字段数据
  31. FieldDesc string // 字段描述
  32. FieldRules string // 字段规则
  33. FieldSort string // 字段排序
  34. FieldWidth string //字段列表显示宽度
  35. fieldAlign string //字段列表对齐
  36. CreateBy string // 创建人
  37. UpdateBy string // 修改人
  38. CreateTime string // 创建时间
  39. UpdateTime string // 修改时间
  40. }{
  41. FieldId: "field_id",
  42. ModelId: "model_id",
  43. FieldName: "field_name",
  44. FieldTitle: "field_title",
  45. FieldType: "field_type",
  46. FieldLength: "field_length",
  47. FieldDefault: "field_default",
  48. FieldData: "field_data",
  49. FieldDesc: "field_desc",
  50. FieldRules: "field_rules",
  51. FieldSort: "field_sort",
  52. FieldWidth: "field_width",
  53. fieldAlign: "field_align",
  54. CreateBy: "create_by",
  55. UpdateBy: "update_by",
  56. CreateTime: "create_time",
  57. UpdateTime: "update_time",
  58. }
  59. )
  60. // FindOne is a convenience method for Model.FindOne.
  61. // See Model.FindOne.
  62. func FindOne(where ...interface{}) (*Entity, error) {
  63. return Model.FindOne(where...)
  64. }
  65. // FindAll is a convenience method for Model.FindAll.
  66. // See Model.FindAll.
  67. func FindAll(where ...interface{}) ([]*Entity, error) {
  68. return Model.FindAll(where...)
  69. }
  70. // FindValue is a convenience method for Model.FindValue.
  71. // See Model.FindValue.
  72. func FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) {
  73. return Model.FindValue(fieldsAndWhere...)
  74. }
  75. // FindArray is a convenience method for Model.FindArray.
  76. // See Model.FindArray.
  77. func FindArray(fieldsAndWhere ...interface{}) ([]gdb.Value, error) {
  78. return Model.FindArray(fieldsAndWhere...)
  79. }
  80. // FindCount is a convenience method for Model.FindCount.
  81. // See Model.FindCount.
  82. func FindCount(where ...interface{}) (int, error) {
  83. return Model.FindCount(where...)
  84. }
  85. // Insert is a convenience method for Model.Insert.
  86. func Insert(data ...interface{}) (result sql.Result, err error) {
  87. return Model.Insert(data...)
  88. }
  89. // InsertIgnore is a convenience method for Model.InsertIgnore.
  90. func InsertIgnore(data ...interface{}) (result sql.Result, err error) {
  91. return Model.InsertIgnore(data...)
  92. }
  93. // Replace is a convenience method for Model.Replace.
  94. func Replace(data ...interface{}) (result sql.Result, err error) {
  95. return Model.Replace(data...)
  96. }
  97. // Save is a convenience method for Model.Save.
  98. func Save(data ...interface{}) (result sql.Result, err error) {
  99. return Model.Save(data...)
  100. }
  101. // Update is a convenience method for Model.Update.
  102. func Update(dataAndWhere ...interface{}) (result sql.Result, err error) {
  103. return Model.Update(dataAndWhere...)
  104. }
  105. // Delete is a convenience method for Model.Delete.
  106. func Delete(where ...interface{}) (result sql.Result, err error) {
  107. return Model.Delete(where...)
  108. }
  109. // As sets an alias name for current table.
  110. func (m *arModel) As(as string) *arModel {
  111. return &arModel{m.M.As(as)}
  112. }
  113. // TX sets the transaction for current operation.
  114. func (m *arModel) TX(tx *gdb.TX) *arModel {
  115. return &arModel{m.M.TX(tx)}
  116. }
  117. // Master marks the following operation on master node.
  118. func (m *arModel) Master() *arModel {
  119. return &arModel{m.M.Master()}
  120. }
  121. // Slave marks the following operation on slave node.
  122. // Note that it makes sense only if there's any slave node configured.
  123. func (m *arModel) Slave() *arModel {
  124. return &arModel{m.M.Slave()}
  125. }
  126. // LeftJoin does "LEFT JOIN ... ON ..." statement on the model.
  127. // The parameter <table> can be joined table and its joined condition,
  128. // and also with its alias name, like:
  129. // Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid")
  130. // Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid")
  131. func (m *arModel) LeftJoin(table ...string) *arModel {
  132. return &arModel{m.M.LeftJoin(table...)}
  133. }
  134. // RightJoin does "RIGHT JOIN ... ON ..." statement on the model.
  135. // The parameter <table> can be joined table and its joined condition,
  136. // and also with its alias name, like:
  137. // Table("user").RightJoin("user_detail", "user_detail.uid=user.uid")
  138. // Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid")
  139. func (m *arModel) RightJoin(table ...string) *arModel {
  140. return &arModel{m.M.RightJoin(table...)}
  141. }
  142. // InnerJoin does "INNER JOIN ... ON ..." statement on the model.
  143. // The parameter <table> can be joined table and its joined condition,
  144. // and also with its alias name, like:
  145. // Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid")
  146. // Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid")
  147. func (m *arModel) InnerJoin(table ...string) *arModel {
  148. return &arModel{m.M.InnerJoin(table...)}
  149. }
  150. // Fields sets the operation fields of the model, multiple fields joined using char ','.
  151. func (m *arModel) Fields(fields string) *arModel {
  152. return &arModel{m.M.Fields(fields)}
  153. }
  154. // FieldsEx sets the excluded operation fields of the model, multiple fields joined using char ','.
  155. func (m *arModel) FieldsEx(fields string) *arModel {
  156. return &arModel{m.M.FieldsEx(fields)}
  157. }
  158. // Option sets the extra operation option for the model.
  159. func (m *arModel) Option(option int) *arModel {
  160. return &arModel{m.M.Option(option)}
  161. }
  162. // OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers
  163. // the data and where attributes for empty values.
  164. func (m *arModel) OmitEmpty() *arModel {
  165. return &arModel{m.M.OmitEmpty()}
  166. }
  167. // Filter marks filtering the fields which does not exist in the fields of the operated table.
  168. func (m *arModel) Filter() *arModel {
  169. return &arModel{m.M.Filter()}
  170. }
  171. // Where sets the condition statement for the model. The parameter <where> can be type of
  172. // string/map/gmap/slice/struct/*struct, etc. Note that, if it's called more than one times,
  173. // multiple conditions will be joined into where statement using "AND".
  174. // Eg:
  175. // Where("uid=10000")
  176. // Where("uid", 10000)
  177. // Where("money>? AND name like ?", 99999, "vip_%")
  178. // Where("uid", 1).Where("name", "john")
  179. // Where("status IN (?)", g.Slice{1,2,3})
  180. // Where("age IN(?,?)", 18, 50)
  181. // Where(User{ Id : 1, UserName : "john"})
  182. func (m *arModel) Where(where interface{}, args ...interface{}) *arModel {
  183. return &arModel{m.M.Where(where, args...)}
  184. }
  185. // And adds "AND" condition to the where statement.
  186. func (m *arModel) And(where interface{}, args ...interface{}) *arModel {
  187. return &arModel{m.M.And(where, args...)}
  188. }
  189. // Or adds "OR" condition to the where statement.
  190. func (m *arModel) Or(where interface{}, args ...interface{}) *arModel {
  191. return &arModel{m.M.Or(where, args...)}
  192. }
  193. // Group sets the "GROUP BY" statement for the model.
  194. func (m *arModel) Group(groupBy string) *arModel {
  195. return &arModel{m.M.Group(groupBy)}
  196. }
  197. // Order sets the "ORDER BY" statement for the model.
  198. func (m *arModel) Order(orderBy ...string) *arModel {
  199. return &arModel{m.M.Order(orderBy...)}
  200. }
  201. // Limit sets the "LIMIT" statement for the model.
  202. // The parameter <limit> can be either one or two number, if passed two number is passed,
  203. // it then sets "LIMIT limit[0],limit[1]" statement for the model, or else it sets "LIMIT limit[0]"
  204. // statement.
  205. func (m *arModel) Limit(limit ...int) *arModel {
  206. return &arModel{m.M.Limit(limit...)}
  207. }
  208. // Offset sets the "OFFSET" statement for the model.
  209. // It only makes sense for some databases like SQLServer, PostgreSQL, etc.
  210. func (m *arModel) Offset(offset int) *arModel {
  211. return &arModel{m.M.Offset(offset)}
  212. }
  213. // Page sets the paging number for the model.
  214. // The parameter <page> is started from 1 for paging.
  215. // Note that, it differs that the Limit function start from 0 for "LIMIT" statement.
  216. func (m *arModel) Page(page, limit int) *arModel {
  217. return &arModel{m.M.Page(page, limit)}
  218. }
  219. // Batch sets the batch operation number for the model.
  220. func (m *arModel) Batch(batch int) *arModel {
  221. return &arModel{m.M.Batch(batch)}
  222. }
  223. // Cache sets the cache feature for the model. It caches the result of the sql, which means
  224. // if there's another same sql request, it just reads and returns the result from cache, it
  225. // but not committed and executed into the database.
  226. //
  227. // If the parameter <duration> < 0, which means it clear the cache with given <name>.
  228. // If the parameter <duration> = 0, which means it never expires.
  229. // If the parameter <duration> > 0, which means it expires after <duration>.
  230. //
  231. // The optional parameter <name> is used to bind a name to the cache, which means you can later
  232. // control the cache like changing the <duration> or clearing the cache with specified <name>.
  233. //
  234. // Note that, the cache feature is disabled if the model is operating on a transaction.
  235. func (m *arModel) Cache(duration time.Duration, name ...string) *arModel {
  236. return &arModel{m.M.Cache(duration, name...)}
  237. }
  238. // Data sets the operation data for the model.
  239. // The parameter <data> can be type of string/map/gmap/slice/struct/*struct, etc.
  240. // Eg:
  241. // Data("uid=10000")
  242. // Data("uid", 10000)
  243. // Data(g.Map{"uid": 10000, "name":"john"})
  244. // Data(g.Slice{g.Map{"uid": 10000, "name":"john"}, g.Map{"uid": 20000, "name":"smith"})
  245. func (m *arModel) Data(data ...interface{}) *arModel {
  246. return &arModel{m.M.Data(data...)}
  247. }
  248. // All does "SELECT FROM ..." statement for the model.
  249. // It retrieves the records from table and returns the result as []*Entity.
  250. // It returns nil if there's no record retrieved with the given conditions from table.
  251. //
  252. // The optional parameter <where> is the same as the parameter of Model.Where function,
  253. // see Model.Where.
  254. func (m *arModel) All(where ...interface{}) ([]*Entity, error) {
  255. all, err := m.M.All(where...)
  256. if err != nil {
  257. return nil, err
  258. }
  259. var entities []*Entity
  260. if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
  261. return nil, err
  262. }
  263. return entities, nil
  264. }
  265. // One retrieves one record from table and returns the result as *Entity.
  266. // It returns nil if there's no record retrieved with the given conditions from table.
  267. //
  268. // The optional parameter <where> is the same as the parameter of Model.Where function,
  269. // see Model.Where.
  270. func (m *arModel) One(where ...interface{}) (*Entity, error) {
  271. one, err := m.M.One(where...)
  272. if err != nil {
  273. return nil, err
  274. }
  275. var entity *Entity
  276. if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
  277. return nil, err
  278. }
  279. return entity, nil
  280. }
  281. // FindOne retrieves and returns a single Record by Model.WherePri and Model.One.
  282. // Also see Model.WherePri and Model.One.
  283. func (m *arModel) FindOne(where ...interface{}) (*Entity, error) {
  284. one, err := m.M.FindOne(where...)
  285. if err != nil {
  286. return nil, err
  287. }
  288. var entity *Entity
  289. if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
  290. return nil, err
  291. }
  292. return entity, nil
  293. }
  294. // FindAll retrieves and returns Result by by Model.WherePri and Model.All.
  295. // Also see Model.WherePri and Model.All.
  296. func (m *arModel) FindAll(where ...interface{}) ([]*Entity, error) {
  297. all, err := m.M.FindAll(where...)
  298. if err != nil {
  299. return nil, err
  300. }
  301. var entities []*Entity
  302. if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
  303. return nil, err
  304. }
  305. return entities, nil
  306. }
  307. // Chunk iterates the table with given size and callback function.
  308. func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error) bool) {
  309. m.M.Chunk(limit, func(result gdb.Result, err error) bool {
  310. var entities []*Entity
  311. err = result.Structs(&entities)
  312. if err == sql.ErrNoRows {
  313. return false
  314. }
  315. return callback(entities, err)
  316. })
  317. }
  318. // LockUpdate sets the lock for update for current operation.
  319. func (m *arModel) LockUpdate() *arModel {
  320. return &arModel{m.M.LockUpdate()}
  321. }
  322. // LockShared sets the lock in share mode for current operation.
  323. func (m *arModel) LockShared() *arModel {
  324. return &arModel{m.M.LockShared()}
  325. }
  326. // Unscoped enables/disables the soft deleting feature.
  327. func (m *arModel) Unscoped() *arModel {
  328. return &arModel{m.M.Unscoped()}
  329. }