sys_config_model.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. // ==========================================================================
  2. // This is auto-generated by gf cli tool. You may not really want to edit it.
  3. // ==========================================================================
  4. package sys_config
  5. import (
  6. "database/sql"
  7. "github.com/gogf/gf/database/gdb"
  8. "github.com/gogf/gf/frame/g"
  9. "time"
  10. )
  11. // arModel is a active record design model for table sys_config operations.
  12. type arModel struct {
  13. M *gdb.Model
  14. }
  15. var (
  16. // Table is the table name of sys_config.
  17. Table = "sys_config"
  18. // Model is the model object of sys_config.
  19. Model = &arModel{g.DB("default").Table(Table).Safe()}
  20. )
  21. // FindOne is a convenience method for Model.FindOne.
  22. // See Model.FindOne.
  23. func FindOne(where ...interface{}) (*Entity, error) {
  24. return Model.FindOne(where...)
  25. }
  26. // FindAll is a convenience method for Model.FindAll.
  27. // See Model.FindAll.
  28. func FindAll(where ...interface{}) ([]*Entity, error) {
  29. return Model.FindAll(where...)
  30. }
  31. // FindValue is a convenience method for Model.FindValue.
  32. // See Model.FindValue.
  33. func FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) {
  34. return Model.FindValue(fieldsAndWhere...)
  35. }
  36. // FindCount is a convenience method for Model.FindCount.
  37. // See Model.FindCount.
  38. func FindCount(where ...interface{}) (int, error) {
  39. return Model.FindCount(where...)
  40. }
  41. // Insert is a convenience method for Model.Insert.
  42. func Insert(data ...interface{}) (result sql.Result, err error) {
  43. return Model.Insert(data...)
  44. }
  45. // Replace is a convenience method for Model.Replace.
  46. func Replace(data ...interface{}) (result sql.Result, err error) {
  47. return Model.Replace(data...)
  48. }
  49. // Save is a convenience method for Model.Save.
  50. func Save(data ...interface{}) (result sql.Result, err error) {
  51. return Model.Save(data...)
  52. }
  53. // Update is a convenience method for Model.Update.
  54. func Update(dataAndWhere ...interface{}) (result sql.Result, err error) {
  55. return Model.Update(dataAndWhere...)
  56. }
  57. // Delete is a convenience method for Model.Delete.
  58. func Delete(where ...interface{}) (result sql.Result, err error) {
  59. return Model.Delete(where...)
  60. }
  61. // As sets an alias name for current table.
  62. func (m *arModel) As(as string) *arModel {
  63. return &arModel{m.M.As(as)}
  64. }
  65. // TX sets the transaction for current operation.
  66. func (m *arModel) TX(tx *gdb.TX) *arModel {
  67. return &arModel{m.M.TX(tx)}
  68. }
  69. // Master marks the following operation on master node.
  70. func (m *arModel) Master() *arModel {
  71. return &arModel{m.M.Master()}
  72. }
  73. // Slave marks the following operation on slave node.
  74. // Note that it makes sense only if there's any slave node configured.
  75. func (m *arModel) Slave() *arModel {
  76. return &arModel{m.M.Slave()}
  77. }
  78. // LeftJoin does "LEFT JOIN ... ON ..." statement on the model.
  79. func (m *arModel) LeftJoin(joinTable string, on string) *arModel {
  80. return &arModel{m.M.LeftJoin(joinTable, on)}
  81. }
  82. // RightJoin does "RIGHT JOIN ... ON ..." statement on the model.
  83. func (m *arModel) RightJoin(joinTable string, on string) *arModel {
  84. return &arModel{m.M.RightJoin(joinTable, on)}
  85. }
  86. // InnerJoin does "INNER JOIN ... ON ..." statement on the model.
  87. func (m *arModel) InnerJoin(joinTable string, on string) *arModel {
  88. return &arModel{m.M.InnerJoin(joinTable, on)}
  89. }
  90. // Fields sets the operation fields of the model, multiple fields joined using char ','.
  91. func (m *arModel) Fields(fields string) *arModel {
  92. return &arModel{m.M.Fields(fields)}
  93. }
  94. // FieldsEx sets the excluded operation fields of the model, multiple fields joined using char ','.
  95. func (m *arModel) FieldsEx(fields string) *arModel {
  96. return &arModel{m.M.FieldsEx(fields)}
  97. }
  98. // Option sets the extra operation option for the model.
  99. func (m *arModel) Option(option int) *arModel {
  100. return &arModel{m.M.Option(option)}
  101. }
  102. // OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers
  103. // the data and where attributes for empty values.
  104. func (m *arModel) OmitEmpty() *arModel {
  105. return &arModel{m.M.OmitEmpty()}
  106. }
  107. // Filter marks filtering the fields which does not exist in the fields of the operated table.
  108. func (m *arModel) Filter() *arModel {
  109. return &arModel{m.M.Filter()}
  110. }
  111. // Where sets the condition statement for the model. The parameter <where> can be type of
  112. // string/map/gmap/slice/struct/*struct, etc. Note that, if it's called more than one times,
  113. // multiple conditions will be joined into where statement using "AND".
  114. // Eg:
  115. // Where("uid=10000")
  116. // Where("uid", 10000)
  117. // Where("money>? AND name like ?", 99999, "vip_%")
  118. // Where("uid", 1).Where("name", "john")
  119. // Where("status IN (?)", g.Slice{1,2,3})
  120. // Where("age IN(?,?)", 18, 50)
  121. // Where(User{ Id : 1, UserName : "john"})
  122. func (m *arModel) Where(where interface{}, args ...interface{}) *arModel {
  123. return &arModel{m.M.Where(where, args...)}
  124. }
  125. // And adds "AND" condition to the where statement.
  126. func (m *arModel) And(where interface{}, args ...interface{}) *arModel {
  127. return &arModel{m.M.And(where, args...)}
  128. }
  129. // Or adds "OR" condition to the where statement.
  130. func (m *arModel) Or(where interface{}, args ...interface{}) *arModel {
  131. return &arModel{m.M.Or(where, args...)}
  132. }
  133. // Group sets the "GROUP BY" statement for the model.
  134. func (m *arModel) Group(groupBy string) *arModel {
  135. return &arModel{m.M.Group(groupBy)}
  136. }
  137. // Order sets the "ORDER BY" statement for the model.
  138. func (m *arModel) Order(orderBy string) *arModel {
  139. return &arModel{m.M.Order(orderBy)}
  140. }
  141. // Limit sets the "LIMIT" statement for the model.
  142. // The parameter <limit> can be either one or two number, if passed two number is passed,
  143. // it then sets "LIMIT limit[0],limit[1]" statement for the model, or else it sets "LIMIT limit[0]"
  144. // statement.
  145. func (m *arModel) Limit(limit ...int) *arModel {
  146. return &arModel{m.M.Limit(limit...)}
  147. }
  148. // Offset sets the "OFFSET" statement for the model.
  149. // It only makes sense for some databases like SQLServer, PostgreSQL, etc.
  150. func (m *arModel) Offset(offset int) *arModel {
  151. return &arModel{m.M.Offset(offset)}
  152. }
  153. // Page sets the paging number for the model.
  154. // The parameter <page> is started from 1 for paging.
  155. // Note that, it differs that the Limit function start from 0 for "LIMIT" statement.
  156. func (m *arModel) Page(page, limit int) *arModel {
  157. return &arModel{m.M.Page(page, limit)}
  158. }
  159. // Batch sets the batch operation number for the model.
  160. func (m *arModel) Batch(batch int) *arModel {
  161. return &arModel{m.M.Batch(batch)}
  162. }
  163. // Cache sets the cache feature for the model. It caches the result of the sql, which means
  164. // if there's another same sql request, it just reads and returns the result from cache, it
  165. // but not committed and executed into the database.
  166. //
  167. // If the parameter <duration> < 0, which means it clear the cache with given <name>.
  168. // If the parameter <duration> = 0, which means it never expires.
  169. // If the parameter <duration> > 0, which means it expires after <duration>.
  170. //
  171. // The optional parameter <name> is used to bind a name to the cache, which means you can later
  172. // control the cache like changing the <duration> or clearing the cache with specified <name>.
  173. //
  174. // Note that, the cache feature is disabled if the model is operating on a transaction.
  175. func (m *arModel) Cache(expire time.Duration, name ...string) *arModel {
  176. return &arModel{m.M.Cache(expire, name...)}
  177. }
  178. // Data sets the operation data for the model.
  179. // The parameter <data> can be type of string/map/gmap/slice/struct/*struct, etc.
  180. // Eg:
  181. // Data("uid=10000")
  182. // Data("uid", 10000)
  183. // Data(g.Map{"uid": 10000, "name":"john"})
  184. // Data(g.Slice{g.Map{"uid": 10000, "name":"john"}, g.Map{"uid": 20000, "name":"smith"})
  185. func (m *arModel) Data(data ...interface{}) *arModel {
  186. return &arModel{m.M.Data(data...)}
  187. }
  188. // Insert does "INSERT INTO ..." statement for the model.
  189. // The optional parameter <data> is the same as the parameter of Model.Data function,
  190. // see Model.Data.
  191. func (m *arModel) Insert(data ...interface{}) (result sql.Result, err error) {
  192. return m.M.Insert(data...)
  193. }
  194. // Replace does "REPLACE INTO ..." statement for the model.
  195. // The optional parameter <data> is the same as the parameter of Model.Data function,
  196. // see Model.Data.
  197. func (m *arModel) Replace(data ...interface{}) (result sql.Result, err error) {
  198. return m.M.Replace(data...)
  199. }
  200. // Save does "INSERT INTO ... ON DUPLICATE KEY UPDATE..." statement for the model.
  201. // It updates the record if there's primary or unique index in the saving data,
  202. // or else it inserts a new record into the table.
  203. //
  204. // The optional parameter <data> is the same as the parameter of Model.Data function,
  205. // see Model.Data.
  206. func (m *arModel) Save(data ...interface{}) (result sql.Result, err error) {
  207. return m.M.Save(data...)
  208. }
  209. // Update does "UPDATE ... " statement for the model.
  210. //
  211. // If the optional parameter <dataAndWhere> is given, the dataAndWhere[0] is the updated
  212. // data field, and dataAndWhere[1:] is treated as where condition fields.
  213. // Also see Model.Data and Model.Where functions.
  214. func (m *arModel) Update(dataAndWhere ...interface{}) (result sql.Result, err error) {
  215. return m.M.Update(dataAndWhere...)
  216. }
  217. // Delete does "DELETE FROM ... " statement for the model.
  218. // The optional parameter <where> is the same as the parameter of Model.Where function,
  219. // see Model.Where.
  220. func (m *arModel) Delete(where ...interface{}) (result sql.Result, err error) {
  221. return m.M.Delete(where...)
  222. }
  223. // Count does "SELECT COUNT(x) FROM ..." statement for the model.
  224. // The optional parameter <where> is the same as the parameter of Model.Where function,
  225. // see Model.Where.
  226. func (m *arModel) Count(where ...interface{}) (int, error) {
  227. return m.M.Count(where...)
  228. }
  229. // All does "SELECT FROM ..." statement for the model.
  230. // It retrieves the records from table and returns the result as []*Entity.
  231. // It returns nil if there's no record retrieved with the given conditions from table.
  232. //
  233. // The optional parameter <where> is the same as the parameter of Model.Where function,
  234. // see Model.Where.
  235. func (m *arModel) All(where ...interface{}) ([]*Entity, error) {
  236. all, err := m.M.All(where...)
  237. if err != nil {
  238. return nil, err
  239. }
  240. var entities []*Entity
  241. if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
  242. return nil, err
  243. }
  244. return entities, nil
  245. }
  246. // One retrieves one record from table and returns the result as *Entity.
  247. // It returns nil if there's no record retrieved with the given conditions from table.
  248. //
  249. // The optional parameter <where> is the same as the parameter of Model.Where function,
  250. // see Model.Where.
  251. func (m *arModel) One(where ...interface{}) (*Entity, error) {
  252. one, err := m.M.One(where...)
  253. if err != nil {
  254. return nil, err
  255. }
  256. var entity *Entity
  257. if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
  258. return nil, err
  259. }
  260. return entity, nil
  261. }
  262. // Value retrieves a specified record value from table and returns the result as interface type.
  263. // It returns nil if there's no record found with the given conditions from table.
  264. //
  265. // If the optional parameter <fieldsAndWhere> is given, the fieldsAndWhere[0] is the selected fields
  266. // and fieldsAndWhere[1:] is treated as where condition fields.
  267. // Also see Model.Fields and Model.Where functions.
  268. func (m *arModel) Value(fieldsAndWhere ...interface{}) (gdb.Value, error) {
  269. return m.M.Value(fieldsAndWhere...)
  270. }
  271. // FindOne retrieves and returns a single Record by Model.WherePri and Model.One.
  272. // Also see Model.WherePri and Model.One.
  273. func (m *arModel) FindOne(where ...interface{}) (*Entity, error) {
  274. one, err := m.M.FindOne(where...)
  275. if err != nil {
  276. return nil, err
  277. }
  278. var entity *Entity
  279. if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
  280. return nil, err
  281. }
  282. return entity, nil
  283. }
  284. // FindAll retrieves and returns Result by by Model.WherePri and Model.All.
  285. // Also see Model.WherePri and Model.All.
  286. func (m *arModel) FindAll(where ...interface{}) ([]*Entity, error) {
  287. all, err := m.M.FindAll(where...)
  288. if err != nil {
  289. return nil, err
  290. }
  291. var entities []*Entity
  292. if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
  293. return nil, err
  294. }
  295. return entities, nil
  296. }
  297. // FindValue retrieves and returns single field value by Model.WherePri and Model.Value.
  298. // Also see Model.WherePri and Model.Value.
  299. func (m *arModel) FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) {
  300. return m.M.FindValue(fieldsAndWhere...)
  301. }
  302. // FindCount retrieves and returns the record number by Model.WherePri and Model.Count.
  303. // Also see Model.WherePri and Model.Count.
  304. func (m *arModel) FindCount(where ...interface{}) (int, error) {
  305. return m.M.FindCount(where...)
  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. }