plug_link_model.go 12 KB

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