sys_user_post.go 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. // ==========================================================================
  2. // This is auto-generated by gf cli tool. DO NOT EDIT THIS FILE MANUALLY.
  3. // ==========================================================================
  4. package internal
  5. import (
  6. "context"
  7. "database/sql"
  8. "github.com/gogf/gf/database/gdb"
  9. "github.com/gogf/gf/frame/g"
  10. "github.com/gogf/gf/frame/gmvc"
  11. "github.com/gogf/gf/util/gconv"
  12. "strings"
  13. "time"
  14. "dashoo.cn/micro/app/model"
  15. )
  16. // SysUserPostDao is the manager for logic model data accessing and custom defined data operations functions management.
  17. type SysUserPostDao struct {
  18. gmvc.M // M is the core and embedded struct that inherits all chaining operations from gdb.Model.
  19. C sysUserPostColumns // C is the short type for Columns, which contains all the column names of Table for convenient usage.
  20. DB gdb.DB // DB is the raw underlying database management object.
  21. Table string // Table is the underlying table name of the DAO.
  22. TableAs string // TableAs is the underlying table alias name of the DAO.
  23. }
  24. // SysUserPostColumns defines and stores column names for table sys_user_post.
  25. type sysUserPostColumns struct {
  26. UserId string // 用户ID
  27. PostId string // 岗位ID
  28. }
  29. var (
  30. // SysUserPost is globally public accessible object for table sys_user_post operations.
  31. SysUserPost = SysUserPostDao{
  32. M: g.DB("default").Model("sys_user_post").Safe(),
  33. DB: g.DB("default"),
  34. Table: "sys_user_post",
  35. C: sysUserPostColumns{
  36. UserId: "user_id",
  37. PostId: "post_id",
  38. },
  39. }
  40. )
  41. func NewSysUserPostDao(tenant string) SysUserPostDao {
  42. var dao SysUserPostDao
  43. dao = SysUserPostDao{
  44. M: g.DB(tenant).Model("sys_user_post").Safe(),
  45. DB: g.DB(tenant),
  46. Table: "sys_user_post",
  47. C: sysUserPostColumns{
  48. UserId: "user_id",
  49. PostId: "post_id",
  50. },
  51. }
  52. return dao
  53. }
  54. // Ctx is a chaining function, which creates and returns a new DB that is a shallow copy
  55. // of current DB object and with given context in it.
  56. // Note that this returned DB object can be used only once, so do not assign it to
  57. // a global or package variable for long using.
  58. func (d *SysUserPostDao) Ctx(ctx context.Context) *SysUserPostDao {
  59. return &SysUserPostDao{M: d.M.Ctx(ctx), Table: d.Table, TableAs: d.TableAs}
  60. }
  61. // GetCtx returns the context for current Model.
  62. // It returns "context.Background() i"s there's no context previously set.
  63. func (d *SysUserPostDao) GetCtx() context.Context {
  64. return d.M.GetCtx()
  65. }
  66. // As sets an alias name for current table.
  67. func (d *SysUserPostDao) As(as string) *SysUserPostDao {
  68. return &SysUserPostDao{M: d.M.As(as), Table: d.Table, TableAs: as}
  69. }
  70. // TX sets the transaction for current operation.
  71. func (d *SysUserPostDao) TX(tx *gdb.TX) *SysUserPostDao {
  72. return &SysUserPostDao{M: d.M.TX(tx), Table: d.Table, TableAs: d.TableAs}
  73. }
  74. // Master marks the following operation on master node.
  75. func (d *SysUserPostDao) Master() *SysUserPostDao {
  76. return &SysUserPostDao{M: d.M.Master(), Table: d.Table, TableAs: d.TableAs}
  77. }
  78. // Slave marks the following operation on slave node.
  79. // Note that it makes sense only if there's any slave node configured.
  80. func (d *SysUserPostDao) Slave() *SysUserPostDao {
  81. return &SysUserPostDao{M: d.M.Slave(), Table: d.Table, TableAs: d.TableAs}
  82. }
  83. // Args sets custom arguments for model operation.
  84. func (d *SysUserPostDao) Args(args ...interface{}) *SysUserPostDao {
  85. return &SysUserPostDao{M: d.M.Args(args...), Table: d.Table, TableAs: d.TableAs}
  86. }
  87. // Handler calls each of "handlers" on current Model and returns a new Model.
  88. // ModelHandler is a function that handles given Model and returns a new Model that is custom modified.
  89. func (d *SysUserPostDao) Handler(handlers ...gdb.ModelHandler) *SysUserPostDao {
  90. return &SysUserPostDao{M: d.M.Handler(handlers...), Table: d.Table, TableAs: d.TableAs}
  91. }
  92. // LeftJoin does "LEFT JOIN ... ON ..." statement on the model.
  93. // The parameter <table> can be joined table and its joined condition,
  94. // and also with its alias name, like:
  95. // Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid")
  96. // Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid")
  97. func (d *SysUserPostDao) LeftJoin(table ...string) *SysUserPostDao {
  98. return &SysUserPostDao{M: d.M.LeftJoin(table...), Table: d.Table, TableAs: d.TableAs}
  99. }
  100. // RightJoin does "RIGHT JOIN ... ON ..." statement on the model.
  101. // The parameter <table> can be joined table and its joined condition,
  102. // and also with its alias name, like:
  103. // Table("user").RightJoin("user_detail", "user_detail.uid=user.uid")
  104. // Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid")
  105. func (d *SysUserPostDao) RightJoin(table ...string) *SysUserPostDao {
  106. return &SysUserPostDao{M: d.M.RightJoin(table...), Table: d.Table, TableAs: d.TableAs}
  107. }
  108. // InnerJoin does "INNER JOIN ... ON ..." statement on the model.
  109. // The parameter <table> can be joined table and its joined condition,
  110. // and also with its alias name, like:
  111. // Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid")
  112. // Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid")
  113. func (d *SysUserPostDao) InnerJoin(table ...string) *SysUserPostDao {
  114. return &SysUserPostDao{M: d.M.InnerJoin(table...), Table: d.Table, TableAs: d.TableAs}
  115. }
  116. // Fields sets the operation fields of the model, multiple fields joined using char ','.
  117. // The parameter <fieldNamesOrMapStruct> can be type of string/map/*map/struct/*struct.
  118. func (d *SysUserPostDao) Fields(fieldNamesOrMapStruct ...interface{}) *SysUserPostDao {
  119. return &SysUserPostDao{M: d.M.Fields(fieldNamesOrMapStruct...), Table: d.Table, TableAs: d.TableAs}
  120. }
  121. // FieldsEx sets the excluded operation fields of the model, multiple fields joined using char ','.
  122. // The parameter <fieldNamesOrMapStruct> can be type of string/map/*map/struct/*struct.
  123. func (d *SysUserPostDao) FieldsEx(fieldNamesOrMapStruct ...interface{}) *SysUserPostDao {
  124. return &SysUserPostDao{M: d.M.FieldsEx(fieldNamesOrMapStruct...), Table: d.Table, TableAs: d.TableAs}
  125. }
  126. // FieldCount formats and appends commonly used field "COUNT(column)" to the select fields of model.
  127. func (d *SysUserPostDao) FieldCount(column string, as ...string) *SysUserPostDao {
  128. return &SysUserPostDao{M: d.M.FieldCount(column, as...), Table: d.Table, TableAs: d.TableAs}
  129. }
  130. // FieldSum formats and appends commonly used field "SUM(column)" to the select fields of model.
  131. func (d *SysUserPostDao) FieldSum(column string, as ...string) *SysUserPostDao {
  132. return &SysUserPostDao{M: d.M.FieldSum(column, as...), Table: d.Table, TableAs: d.TableAs}
  133. }
  134. // FieldMin formats and appends commonly used field "MIN(column)" to the select fields of model.
  135. func (d *SysUserPostDao) FieldMin(column string, as ...string) *SysUserPostDao {
  136. return &SysUserPostDao{M: d.M.FieldMin(column, as...), Table: d.Table, TableAs: d.TableAs}
  137. }
  138. // FieldMax formats and appends commonly used field "MAX(column)" to the select fields of model.
  139. func (d *SysUserPostDao) FieldMax(column string, as ...string) *SysUserPostDao {
  140. return &SysUserPostDao{M: d.M.FieldMax(column, as...), Table: d.Table, TableAs: d.TableAs}
  141. }
  142. // FieldAvg formats and appends commonly used field "AVG(column)" to the select fields of model.
  143. func (d *SysUserPostDao) FieldAvg(column string, as ...string) *SysUserPostDao {
  144. return &SysUserPostDao{M: d.M.FieldAvg(column, as...), Table: d.Table, TableAs: d.TableAs}
  145. }
  146. // Option adds extra operation option for the model.
  147. // Deprecated, use separate operations instead.
  148. func (d *SysUserPostDao) Option(option int) *SysUserPostDao {
  149. return &SysUserPostDao{M: d.M.Option(option), Table: d.Table, TableAs: d.TableAs}
  150. }
  151. // OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers
  152. // the data and where attributes for empty values.
  153. func (d *SysUserPostDao) OmitEmpty() *SysUserPostDao {
  154. return &SysUserPostDao{M: d.M.OmitEmpty(), Table: d.Table, TableAs: d.TableAs}
  155. }
  156. // OmitEmptyWhere sets optionOmitEmptyWhere option for the model, which automatically filers
  157. // the Where/Having parameters for "empty" values.
  158. func (d *SysUserPostDao) OmitEmptyWhere() *SysUserPostDao {
  159. return &SysUserPostDao{M: d.M.OmitEmptyWhere(), Table: d.Table, TableAs: d.TableAs}
  160. }
  161. // OmitEmptyData sets optionOmitEmptyData option for the model, which automatically filers
  162. // the Data parameters for "empty" values.
  163. func (d *SysUserPostDao) OmitEmptyData() *SysUserPostDao {
  164. return &SysUserPostDao{M: d.M.OmitEmptyData(), Table: d.Table, TableAs: d.TableAs}
  165. }
  166. // OmitNil sets optionOmitNil option for the model, which automatically filers
  167. // the data and where parameters for "nil" values.
  168. func (d *SysUserPostDao) OmitNil() *SysUserPostDao {
  169. return &SysUserPostDao{M: d.M.OmitNil(), Table: d.Table, TableAs: d.TableAs}
  170. }
  171. // OmitNilWhere sets optionOmitNilWhere option for the model, which automatically filers
  172. // the Where/Having parameters for "nil" values.
  173. func (d *SysUserPostDao) OmitNilWhere() *SysUserPostDao {
  174. return &SysUserPostDao{M: d.M.OmitNilWhere(), Table: d.Table, TableAs: d.TableAs}
  175. }
  176. // OmitNilData sets optionOmitNilData option for the model, which automatically filers
  177. // the Data parameters for "nil" values.
  178. func (d *SysUserPostDao) OmitNilData() *SysUserPostDao {
  179. return &SysUserPostDao{M: d.M.OmitNilData(), Table: d.Table, TableAs: d.TableAs}
  180. }
  181. // Filter marks filtering the fields which does not exist in the fields of the operated table.
  182. // Note that this function supports only single table operations.
  183. // Deprecated, filter feature is automatically enabled from GoFrame v1.16.0, it is so no longer used.
  184. func (d *SysUserPostDao) Filter() *SysUserPostDao {
  185. return &SysUserPostDao{M: d.M.Filter(), Table: d.Table, TableAs: d.TableAs}
  186. }
  187. // Where sets the condition statement for the model. The parameter <where> can be type of
  188. // string/map/gmap/slice/struct/*struct, etc. Note that, if it's called more than one times,
  189. // multiple conditions will be joined into where statement using "AND".
  190. // Eg:
  191. // Where("uid=10000")
  192. // Where("uid", 10000)
  193. // Where("money>? AND name like ?", 99999, "vip_%")
  194. // Where("uid", 1).Where("name", "john")
  195. // Where("status IN (?)", g.Slice{1,2,3})
  196. // Where("age IN(?,?)", 18, 50)
  197. // Where(User{ Id : 1, UserName : "john"})
  198. func (d *SysUserPostDao) Where(where interface{}, args ...interface{}) *SysUserPostDao {
  199. return &SysUserPostDao{M: d.M.Where(where, args...), Table: d.Table, TableAs: d.TableAs}
  200. }
  201. // WherePri does the same logic as M.Where except that if the parameter <where>
  202. // is a single condition like int/string/float/slice, it treats the condition as the primary
  203. // key value. That is, if primary key is "id" and given <where> parameter as "123", the
  204. // WherePri function treats the condition as "id=123", but M.Where treats the condition
  205. // as string "123".
  206. func (d *SysUserPostDao) WherePri(where interface{}, args ...interface{}) *SysUserPostDao {
  207. return &SysUserPostDao{M: d.M.WherePri(where, args...), Table: d.Table, TableAs: d.TableAs}
  208. }
  209. // Having sets the having statement for the model.
  210. // The parameters of this function usage are as the same as function Where.
  211. // See Where.
  212. func (d *SysUserPostDao) Having(having interface{}, args ...interface{}) *SysUserPostDao {
  213. return &SysUserPostDao{M: d.M.Having(having, args...), Table: d.Table, TableAs: d.TableAs}
  214. }
  215. // Wheref builds condition string using fmt.Sprintf and arguments.
  216. // Note that if the number of "args" is more than the place holder in "format",
  217. // the extra "args" will be used as the where condition arguments of the Model.
  218. func (d *SysUserPostDao) Wheref(format string, args ...interface{}) *SysUserPostDao {
  219. return &SysUserPostDao{M: d.M.Wheref(format, args...), Table: d.Table, TableAs: d.TableAs}
  220. }
  221. // WhereLT builds "column < value" statement.
  222. func (d *SysUserPostDao) WhereLT(column string, value interface{}) *SysUserPostDao {
  223. return &SysUserPostDao{M: d.M.WhereLT(column, value), Table: d.Table, TableAs: d.TableAs}
  224. }
  225. // WhereLTE builds "column <= value" statement.
  226. func (d *SysUserPostDao) WhereLTE(column string, value interface{}) *SysUserPostDao {
  227. return &SysUserPostDao{M: d.M.WhereLTE(column, value), Table: d.Table, TableAs: d.TableAs}
  228. }
  229. // WhereGT builds "column > value" statement.
  230. func (d *SysUserPostDao) WhereGT(column string, value interface{}) *SysUserPostDao {
  231. return &SysUserPostDao{M: d.M.WhereGT(column, value), Table: d.Table, TableAs: d.TableAs}
  232. }
  233. // WhereGTE builds "column >= value" statement.
  234. func (d *SysUserPostDao) WhereGTE(column string, value interface{}) *SysUserPostDao {
  235. return &SysUserPostDao{M: d.M.WhereGTE(column, value), Table: d.Table, TableAs: d.TableAs}
  236. }
  237. // WhereBetween builds "column BETWEEN min AND max" statement.
  238. func (d *SysUserPostDao) WhereBetween(column string, min, max interface{}) *SysUserPostDao {
  239. return &SysUserPostDao{M: d.M.WhereBetween(column, min, max), Table: d.Table, TableAs: d.TableAs}
  240. }
  241. // WhereLike builds "column LIKE like" statement.
  242. func (d *SysUserPostDao) WhereLike(column string, like interface{}) *SysUserPostDao {
  243. return &SysUserPostDao{M: d.M.WhereLike(column, like), Table: d.Table, TableAs: d.TableAs}
  244. }
  245. // WhereIn builds "column IN (in)" statement.
  246. func (d *SysUserPostDao) WhereIn(column string, in interface{}) *SysUserPostDao {
  247. return &SysUserPostDao{M: d.M.WhereIn(column, in), Table: d.Table, TableAs: d.TableAs}
  248. }
  249. // WhereNull builds "columns[0] IS NULL AND columns[1] IS NULL ..." statement.
  250. func (d *SysUserPostDao) WhereNull(columns ...string) *SysUserPostDao {
  251. return &SysUserPostDao{M: d.M.WhereNull(columns...), Table: d.Table, TableAs: d.TableAs}
  252. }
  253. // WhereNotBetween builds "column NOT BETWEEN min AND max" statement.
  254. func (d *SysUserPostDao) WhereNotBetween(column string, min, max interface{}) *SysUserPostDao {
  255. return &SysUserPostDao{M: d.M.WhereNotBetween(column, min, max), Table: d.Table, TableAs: d.TableAs}
  256. }
  257. // WhereNotLike builds "column NOT LIKE like" statement.
  258. func (d *SysUserPostDao) WhereNotLike(column string, like interface{}) *SysUserPostDao {
  259. return &SysUserPostDao{M: d.M.WhereNotLike(column, like), Table: d.Table, TableAs: d.TableAs}
  260. }
  261. // WhereNot builds "column != value" statement.
  262. func (d *SysUserPostDao) WhereNot(column string, value interface{}) *SysUserPostDao {
  263. return &SysUserPostDao{M: d.M.WhereNot(column, value), Table: d.Table, TableAs: d.TableAs}
  264. }
  265. // WhereNotIn builds "column NOT IN (in)" statement.
  266. func (d *SysUserPostDao) WhereNotIn(column string, in interface{}) *SysUserPostDao {
  267. return &SysUserPostDao{M: d.M.WhereNotIn(column, in), Table: d.Table, TableAs: d.TableAs}
  268. }
  269. // WhereNotNull builds "columns[0] IS NOT NULL AND columns[1] IS NOT NULL ..." statement.
  270. func (d *SysUserPostDao) WhereNotNull(columns ...string) *SysUserPostDao {
  271. return &SysUserPostDao{M: d.M.WhereNotNull(columns...), Table: d.Table, TableAs: d.TableAs}
  272. }
  273. // WhereOr adds "OR" condition to the where statement.
  274. func (d *SysUserPostDao) WhereOr(where interface{}, args ...interface{}) *SysUserPostDao {
  275. return &SysUserPostDao{M: d.M.WhereOr(where, args...), Table: d.Table, TableAs: d.TableAs}
  276. }
  277. // WhereOrf builds "OR" condition string using fmt.Sprintf and arguments.
  278. func (d *SysUserPostDao) WhereOrf(format string, args ...interface{}) *SysUserPostDao {
  279. return &SysUserPostDao{M: d.M.WhereOrf(format, args...), Table: d.Table, TableAs: d.TableAs}
  280. }
  281. // WhereOrLT builds "column < value" statement in "OR" conditions..
  282. func (d *SysUserPostDao) WhereOrLT(column string, value interface{}) *SysUserPostDao {
  283. return &SysUserPostDao{M: d.M.WhereOrLT(column, value), Table: d.Table, TableAs: d.TableAs}
  284. }
  285. // WhereOrLTE builds "column <= value" statement in "OR" conditions..
  286. func (d *SysUserPostDao) WhereOrLTE(column string, value interface{}) *SysUserPostDao {
  287. return &SysUserPostDao{M: d.M.WhereOrLTE(column, value), Table: d.Table, TableAs: d.TableAs}
  288. }
  289. // WhereOrGT builds "column > value" statement in "OR" conditions..
  290. func (d *SysUserPostDao) WhereOrGT(column string, value interface{}) *SysUserPostDao {
  291. return &SysUserPostDao{M: d.M.WhereOrGT(column, value), Table: d.Table, TableAs: d.TableAs}
  292. }
  293. // WhereOrGTE builds "column >= value" statement in "OR" conditions..
  294. func (d *SysUserPostDao) WhereOrGTE(column string, value interface{}) *SysUserPostDao {
  295. return &SysUserPostDao{M: d.M.WhereOrGTE(column, value), Table: d.Table, TableAs: d.TableAs}
  296. }
  297. // WhereOrBetween builds "column BETWEEN min AND max" statement in "OR" conditions.
  298. func (d *SysUserPostDao) WhereOrBetween(column string, min, max interface{}) *SysUserPostDao {
  299. return &SysUserPostDao{M: d.M.WhereOrBetween(column, min, max), Table: d.Table, TableAs: d.TableAs}
  300. }
  301. // WhereOrLike builds "column LIKE like" statement in "OR" conditions.
  302. func (d *SysUserPostDao) WhereOrLike(column string, like interface{}) *SysUserPostDao {
  303. return &SysUserPostDao{M: d.M.WhereOrLike(column, like), Table: d.Table, TableAs: d.TableAs}
  304. }
  305. // WhereOrIn builds "column IN (in)" statement in "OR" conditions.
  306. func (d *SysUserPostDao) WhereOrIn(column string, in interface{}) *SysUserPostDao {
  307. return &SysUserPostDao{M: d.M.WhereOrIn(column, in), Table: d.Table, TableAs: d.TableAs}
  308. }
  309. // WhereOrNull builds "columns[0] IS NULL OR columns[1] IS NULL ..." statement in "OR" conditions.
  310. func (d *SysUserPostDao) WhereOrNull(columns ...string) *SysUserPostDao {
  311. return &SysUserPostDao{M: d.M.WhereOrNull(columns...), Table: d.Table, TableAs: d.TableAs}
  312. }
  313. // WhereOrNotBetween builds "column NOT BETWEEN min AND max" statement in "OR" conditions.
  314. func (d *SysUserPostDao) WhereOrNotBetween(column string, min, max interface{}) *SysUserPostDao {
  315. return &SysUserPostDao{M: d.M.WhereOrNotBetween(column, min, max), Table: d.Table, TableAs: d.TableAs}
  316. }
  317. // WhereOrNotLike builds "column NOT LIKE like" statement in "OR" conditions.
  318. func (d *SysUserPostDao) WhereOrNotLike(column string, like interface{}) *SysUserPostDao {
  319. return &SysUserPostDao{M: d.M.WhereOrNotLike(column, like), Table: d.Table, TableAs: d.TableAs}
  320. }
  321. // WhereOrNotIn builds "column NOT IN (in)" statement.
  322. func (d *SysUserPostDao) WhereOrNotIn(column string, in interface{}) *SysUserPostDao {
  323. return &SysUserPostDao{M: d.M.WhereOrNotIn(column, in), Table: d.Table, TableAs: d.TableAs}
  324. }
  325. // WhereOrNotNull builds "columns[0] IS NOT NULL OR columns[1] IS NOT NULL ..." statement in "OR" conditions.
  326. func (d *SysUserPostDao) WhereOrNotNull(columns ...string) *SysUserPostDao {
  327. return &SysUserPostDao{M: d.M.WhereOrNotNull(columns...), Table: d.Table, TableAs: d.TableAs}
  328. }
  329. // Group sets the "GROUP BY" statement for the model.
  330. func (d *SysUserPostDao) Group(groupBy ...string) *SysUserPostDao {
  331. return &SysUserPostDao{M: d.M.Group(groupBy...), Table: d.Table, TableAs: d.TableAs}
  332. }
  333. // And adds "AND" condition to the where statement.
  334. // Deprecated, use Where instead.
  335. func (d *SysUserPostDao) And(where interface{}, args ...interface{}) *SysUserPostDao {
  336. return &SysUserPostDao{M: d.M.And(where, args...), Table: d.Table, TableAs: d.TableAs}
  337. }
  338. // Or adds "OR" condition to the where statement.
  339. // Deprecated, use WhereOr instead.
  340. func (d *SysUserPostDao) Or(where interface{}, args ...interface{}) *SysUserPostDao {
  341. return &SysUserPostDao{M: d.M.Or(where, args...), Table: d.Table, TableAs: d.TableAs}
  342. }
  343. // GroupBy sets the "GROUP BY" statement for the model.
  344. func (d *SysUserPostDao) GroupBy(groupBy string) *SysUserPostDao {
  345. return &SysUserPostDao{M: d.M.Group(groupBy), Table: d.Table, TableAs: d.TableAs}
  346. }
  347. // Order sets the "ORDER BY" statement for the model.
  348. func (d *SysUserPostDao) Order(orderBy ...string) *SysUserPostDao {
  349. return &SysUserPostDao{M: d.M.Order(orderBy...), Table: d.Table, TableAs: d.TableAs}
  350. }
  351. // OrderAsc sets the "ORDER BY xxx ASC" statement for the model.
  352. func (d *SysUserPostDao) OrderAsc(column string) *SysUserPostDao {
  353. return &SysUserPostDao{M: d.M.OrderAsc(column), Table: d.Table, TableAs: d.TableAs}
  354. }
  355. // OrderDesc sets the "ORDER BY xxx DESC" statement for the model.
  356. func (d *SysUserPostDao) OrderDesc(column string) *SysUserPostDao {
  357. return &SysUserPostDao{M: d.M.OrderDesc(column), Table: d.Table, TableAs: d.TableAs}
  358. }
  359. // OrderRandom sets the "ORDER BY RANDOM()" statement for the model.
  360. func (d *SysUserPostDao) OrderRandom() *SysUserPostDao {
  361. return &SysUserPostDao{M: d.M.OrderRandom(), Table: d.Table, TableAs: d.TableAs}
  362. }
  363. // OrderBy is alias of Model.Order.
  364. // See Model.Order.
  365. // Deprecated, use Order instead.
  366. func (d *SysUserPostDao) OrderBy(orderBy string) *SysUserPostDao {
  367. return &SysUserPostDao{M: d.M.Order(orderBy), Table: d.Table, TableAs: d.TableAs}
  368. }
  369. // Limit sets the "LIMIT" statement for the model.
  370. // The parameter <limit> can be either one or two number, if passed two number is passed,
  371. // it then sets "LIMIT limit[0],limit[1]" statement for the model, or else it sets "LIMIT limit[0]"
  372. // statement.
  373. func (d *SysUserPostDao) Limit(limit ...int) *SysUserPostDao {
  374. return &SysUserPostDao{M: d.M.Limit(limit...), Table: d.Table, TableAs: d.TableAs}
  375. }
  376. // Offset sets the "OFFSET" statement for the model.
  377. // It only makes sense for some databases like SQLServer, PostgreSQL, etc.
  378. func (d *SysUserPostDao) Offset(offset int) *SysUserPostDao {
  379. return &SysUserPostDao{M: d.M.Offset(offset), Table: d.Table, TableAs: d.TableAs}
  380. }
  381. // Distinct forces the query to only return distinct results.
  382. func (d *SysUserPostDao) Distinct() *SysUserPostDao {
  383. return &SysUserPostDao{M: d.M.Distinct(), Table: d.Table, TableAs: d.TableAs}
  384. }
  385. // Page sets the paging number for the model.
  386. // The parameter <page> is started from 1 for paging.
  387. // Note that, it differs that the Limit function start from 0 for "LIMIT" statement.
  388. func (d *SysUserPostDao) Page(page, limit int) *SysUserPostDao {
  389. return &SysUserPostDao{M: d.M.Page(page, limit), Table: d.Table, TableAs: d.TableAs}
  390. }
  391. // Batch sets the batch operation number for the model.
  392. func (d *SysUserPostDao) Batch(batch int) *SysUserPostDao {
  393. return &SysUserPostDao{M: d.M.Batch(batch), Table: d.Table, TableAs: d.TableAs}
  394. }
  395. // Cache sets the cache feature for the model. It caches the result of the sql, which means
  396. // if there's another same sql request, it just reads and returns the result from cache, it
  397. // but not committed and executed into the database.
  398. //
  399. // If the parameter <duration> < 0, which means it clear the cache with given <name>.
  400. // If the parameter <duration> = 0, which means it never expires.
  401. // If the parameter <duration> > 0, which means it expires after <duration>.
  402. //
  403. // The optional parameter <name> is used to bind a name to the cache, which means you can later
  404. // control the cache like changing the <duration> or clearing the cache with specified <name>.
  405. //
  406. // Note that, the cache feature is disabled if the model is operating on a transaction.
  407. func (d *SysUserPostDao) Cache(duration time.Duration, name ...string) *SysUserPostDao {
  408. return &SysUserPostDao{M: d.M.Cache(duration, name...), Table: d.Table, TableAs: d.TableAs}
  409. }
  410. // Data sets the operation data for the model.
  411. // The parameter <data> can be type of string/map/gmap/slice/struct/*struct, etc.
  412. // Eg:
  413. // Data("uid=10000")
  414. // Data("uid", 10000)
  415. // Data(g.Map{"uid": 10000, "name":"john"})
  416. // Data(g.Slice{g.Map{"uid": 10000, "name":"john"}, g.Map{"uid": 20000, "name":"smith"})
  417. func (d *SysUserPostDao) Data(data ...interface{}) *SysUserPostDao {
  418. return &SysUserPostDao{M: d.M.Data(data...), Table: d.Table, TableAs: d.TableAs}
  419. }
  420. // All does "SELECT FROM ..." statement for the model.
  421. // It retrieves the records from table and returns the result as []*model.SysUserPost.
  422. // It returns nil if there's no record retrieved with the given conditions from table.
  423. //
  424. // The optional parameter <where> is the same as the parameter of M.Where function,
  425. // see M.Where.
  426. func (d *SysUserPostDao) All(where ...interface{}) ([]*model.SysUserPost, error) {
  427. all, err := d.M.All(where...)
  428. if err != nil {
  429. return nil, err
  430. }
  431. var entities []*model.SysUserPost
  432. if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
  433. return nil, err
  434. }
  435. return entities, nil
  436. }
  437. // One retrieves one record from table and returns the result as *model.SysUserPost.
  438. // It returns nil if there's no record retrieved with the given conditions from table.
  439. //
  440. // The optional parameter <where> is the same as the parameter of M.Where function,
  441. // see M.Where.
  442. func (d *SysUserPostDao) One(where ...interface{}) (*model.SysUserPost, error) {
  443. one, err := d.M.One(where...)
  444. if err != nil {
  445. return nil, err
  446. }
  447. var entity *model.SysUserPost
  448. if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
  449. return nil, err
  450. }
  451. return entity, nil
  452. }
  453. // FindOne retrieves and returns a single Record by M.WherePri and M.One.
  454. // Also see M.WherePri and M.One.
  455. func (d *SysUserPostDao) FindOne(where ...interface{}) (*model.SysUserPost, error) {
  456. one, err := d.M.FindOne(where...)
  457. if err != nil {
  458. return nil, err
  459. }
  460. var entity *model.SysUserPost
  461. if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
  462. return nil, err
  463. }
  464. return entity, nil
  465. }
  466. // FindAll retrieves and returns Result by by M.WherePri and M.All.
  467. // Also see M.WherePri and M.All.
  468. func (d *SysUserPostDao) FindAll(where ...interface{}) ([]*model.SysUserPost, error) {
  469. all, err := d.M.FindAll(where...)
  470. if err != nil {
  471. return nil, err
  472. }
  473. var entities []*model.SysUserPost
  474. if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
  475. return nil, err
  476. }
  477. return entities, nil
  478. }
  479. // Struct retrieves one record from table and converts it into given struct.
  480. // The parameter <pointer> should be type of *struct/**struct. If type **struct is given,
  481. // it can create the struct internally during converting.
  482. //
  483. // The optional parameter <where> is the same as the parameter of Model.Where function,
  484. // see Model.Where.
  485. //
  486. // Note that it returns sql.ErrNoRows if there's no record retrieved with the given conditions
  487. // from table and <pointer> is not nil.
  488. //
  489. // Eg:
  490. // user := new(User)
  491. // err := dao.User.Where("id", 1).Struct(user)
  492. //
  493. // user := (*User)(nil)
  494. // err := dao.User.Where("id", 1).Struct(&user)
  495. func (d *SysUserPostDao) Struct(pointer interface{}, where ...interface{}) error {
  496. return d.M.Struct(pointer, where...)
  497. }
  498. // Structs retrieves records from table and converts them into given struct slice.
  499. // The parameter <pointer> should be type of *[]struct/*[]*struct. It can create and fill the struct
  500. // slice internally during converting.
  501. //
  502. // The optional parameter <where> is the same as the parameter of Model.Where function,
  503. // see Model.Where.
  504. //
  505. // Note that it returns sql.ErrNoRows if there's no record retrieved with the given conditions
  506. // from table and <pointer> is not empty.
  507. //
  508. // Eg:
  509. // users := ([]User)(nil)
  510. // err := dao.User.Structs(&users)
  511. //
  512. // users := ([]*User)(nil)
  513. // err := dao.User.Structs(&users)
  514. func (d *SysUserPostDao) Structs(pointer interface{}, where ...interface{}) error {
  515. return d.M.Structs(pointer, where...)
  516. }
  517. // Scan automatically calls Struct or Structs function according to the type of parameter <pointer>.
  518. // It calls function Struct if <pointer> is type of *struct/**struct.
  519. // It calls function Structs if <pointer> is type of *[]struct/*[]*struct.
  520. //
  521. // The optional parameter <where> is the same as the parameter of Model.Where function,
  522. // see Model.Where.
  523. //
  524. // Note that it returns sql.ErrNoRows if there's no record retrieved and given pointer is not empty or nil.
  525. //
  526. // Eg:
  527. // user := new(User)
  528. // err := dao.User.Where("id", 1).Scan(user)
  529. //
  530. // user := (*User)(nil)
  531. // err := dao.User.Where("id", 1).Scan(&user)
  532. //
  533. // users := ([]User)(nil)
  534. // err := dao.User.Scan(&users)
  535. //
  536. // users := ([]*User)(nil)
  537. // err := dao.User.Scan(&users)
  538. func (d *SysUserPostDao) Scan(pointer interface{}, where ...interface{}) error {
  539. return d.M.Scan(pointer, where...)
  540. }
  541. // Chunk iterates the table with given size and callback function.
  542. func (d *SysUserPostDao) Chunk(limit int, callback func(entities []*model.SysUserPost, err error) bool) {
  543. d.M.Chunk(limit, func(result gdb.Result, err error) bool {
  544. var entities []*model.SysUserPost
  545. err = result.Structs(&entities)
  546. if err == sql.ErrNoRows {
  547. return false
  548. }
  549. return callback(entities, err)
  550. })
  551. }
  552. // LockUpdate sets the lock for update for current operation.
  553. func (d *SysUserPostDao) LockUpdate() *SysUserPostDao {
  554. return &SysUserPostDao{M: d.M.LockUpdate(), Table: d.Table, TableAs: d.TableAs}
  555. }
  556. // LockShared sets the lock in share mode for current operation.
  557. func (d *SysUserPostDao) LockShared() *SysUserPostDao {
  558. return &SysUserPostDao{M: d.M.LockShared(), Table: d.Table, TableAs: d.TableAs}
  559. }
  560. // Unscoped enables/disables the soft deleting feature.
  561. func (d *SysUserPostDao) Unscoped() *SysUserPostDao {
  562. return &SysUserPostDao{M: d.M.Unscoped(), Table: d.Table, TableAs: d.TableAs}
  563. }
  564. // DataScope enables the DataScope feature.
  565. func (d *SysUserPostDao) DataScope(ctx context.Context, userCol ...string) *SysUserPostDao {
  566. cs := ctx.Value("contextService")
  567. dataScope := gconv.Map(cs)["dataScope"].(g.Map)
  568. if dataScope != nil {
  569. userIds, ok := dataScope["userIds"]
  570. delete(dataScope, "userIds")
  571. var columns []string
  572. var values []interface{}
  573. if ok && userIds != "-1" {
  574. column := "created_by"
  575. if len(userCol) == 1 {
  576. column = userCol[0]
  577. }
  578. dataScope[column] = userIds
  579. if d.Table == "sys_user" {
  580. dataScope["id"] = userIds
  581. }
  582. }
  583. tableAs := d.TableAs
  584. if d.TableAs != "" {
  585. tableAs += "."
  586. }
  587. for k, v := range dataScope {
  588. if ok, _ := d.M.HasField(k); ok {
  589. columns = append(columns, tableAs+k+" IN (?) ")
  590. values = append(values, v)
  591. }
  592. }
  593. whereSql := strings.Join(columns, " OR ")
  594. return &SysUserPostDao{M: d.M.Where(whereSql, values).Ctx(ctx), Table: d.Table, TableAs: d.TableAs}
  595. }
  596. return d
  597. }