web_set_model.go 11 KB

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