sys_login.go 29 KB

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