6
0

base_account.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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. model2 "lims_adapter/model/account"
  12. "time"
  13. )
  14. // BaseAccountDao is the manager for logic model data accessing
  15. // and custom defined data operations functions management.
  16. type BaseAccountDao struct {
  17. gmvc.M
  18. DB gdb.DB
  19. Table string
  20. Columns baseAccountColumns
  21. }
  22. // BaseAccountColumns defines and stores column names for table base_account.
  23. type baseAccountColumns struct {
  24. Id string // 主键
  25. Account string // 账户
  26. AccountName string // 账户名称
  27. Surplus string // 账户余额
  28. Available string // 可用余额
  29. Limit string // 使用限额
  30. Advance string // 优先级
  31. DeletedAt string
  32. }
  33. var (
  34. // BaseAccount is globally public accessible object for table base_account operations.
  35. BaseAccount = BaseAccountDao{
  36. M: g.DB("default").Model("base_account").Safe(),
  37. DB: g.DB("default"),
  38. Table: "base_account",
  39. Columns: baseAccountColumns{
  40. Id: "Id",
  41. Account: "Account",
  42. AccountName: "AccountName",
  43. Surplus: "Surplus",
  44. Available: "Available",
  45. Limit: "Limit",
  46. Advance: "Advance",
  47. DeletedAt: "deletedAt",
  48. },
  49. }
  50. )
  51. func NewBaseAccountDao(tenant string) BaseAccountDao {
  52. var dao BaseAccountDao
  53. dao = BaseAccountDao{
  54. M: g.DB(tenant).Model("base_account").Safe(),
  55. DB: g.DB(tenant),
  56. Table: "base_account",
  57. Columns: baseAccountColumns{
  58. Id: "Id",
  59. Account: "Account",
  60. AccountName: "AccountName",
  61. Surplus: "Surplus",
  62. Available: "Available",
  63. Limit: "Limit",
  64. Advance: "Advance",
  65. DeletedAt: "deletedAt",
  66. },
  67. }
  68. return dao
  69. }
  70. // Ctx is a chaining function, which creates and returns a new DB that is a shallow copy
  71. // of current DB object and with given context in it.
  72. // Note that this returned DB object can be used only once, so do not assign it to
  73. // a global or package variable for long using.
  74. func (d *BaseAccountDao) Ctx(ctx context.Context) *BaseAccountDao {
  75. return &BaseAccountDao{M: d.M.Ctx(ctx)}
  76. }
  77. // As sets an alias name for current table.
  78. func (d *BaseAccountDao) As(as string) *BaseAccountDao {
  79. return &BaseAccountDao{M: d.M.As(as)}
  80. }
  81. // TX sets the transaction for current operation.
  82. func (d *BaseAccountDao) TX(tx *gdb.TX) *BaseAccountDao {
  83. return &BaseAccountDao{M: d.M.TX(tx)}
  84. }
  85. // Master marks the following operation on master node.
  86. func (d *BaseAccountDao) Master() *BaseAccountDao {
  87. return &BaseAccountDao{M: d.M.Master()}
  88. }
  89. // Slave marks the following operation on slave node.
  90. // Note that it makes sense only if there's any slave node configured.
  91. func (d *BaseAccountDao) Slave() *BaseAccountDao {
  92. return &BaseAccountDao{M: d.M.Slave()}
  93. }
  94. // Args sets custom arguments for model operation.
  95. func (d *BaseAccountDao) Args(args ...interface{}) *BaseAccountDao {
  96. return &BaseAccountDao{M: d.M.Args(args...)}
  97. }
  98. // LeftJoin does "LEFT JOIN ... ON ..." statement on the model.
  99. // The parameter <table> can be joined table and its joined condition,
  100. // and also with its alias name, like:
  101. // Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid")
  102. // Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid")
  103. func (d *BaseAccountDao) LeftJoin(table ...string) *BaseAccountDao {
  104. return &BaseAccountDao{M: d.M.LeftJoin(table...)}
  105. }
  106. // RightJoin does "RIGHT JOIN ... ON ..." statement on the model.
  107. // The parameter <table> can be joined table and its joined condition,
  108. // and also with its alias name, like:
  109. // Table("user").RightJoin("user_detail", "user_detail.uid=user.uid")
  110. // Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid")
  111. func (d *BaseAccountDao) RightJoin(table ...string) *BaseAccountDao {
  112. return &BaseAccountDao{M: d.M.RightJoin(table...)}
  113. }
  114. // InnerJoin does "INNER JOIN ... ON ..." statement on the model.
  115. // The parameter <table> can be joined table and its joined condition,
  116. // and also with its alias name, like:
  117. // Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid")
  118. // Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid")
  119. func (d *BaseAccountDao) InnerJoin(table ...string) *BaseAccountDao {
  120. return &BaseAccountDao{M: d.M.InnerJoin(table...)}
  121. }
  122. // Fields sets the operation fields of the model, multiple fields joined using char ','.
  123. // The parameter <fieldNamesOrMapStruct> can be type of string/map/*map/struct/*struct.
  124. func (d *BaseAccountDao) Fields(fieldNamesOrMapStruct ...interface{}) *BaseAccountDao {
  125. return &BaseAccountDao{M: d.M.Fields(fieldNamesOrMapStruct...)}
  126. }
  127. // FieldsEx sets the excluded operation fields of the model, multiple fields joined using char ','.
  128. // The parameter <fieldNamesOrMapStruct> can be type of string/map/*map/struct/*struct.
  129. func (d *BaseAccountDao) FieldsEx(fieldNamesOrMapStruct ...interface{}) *BaseAccountDao {
  130. return &BaseAccountDao{M: d.M.FieldsEx(fieldNamesOrMapStruct...)}
  131. }
  132. // Option sets the extra operation option for the model.
  133. func (d *BaseAccountDao) Option(option int) *BaseAccountDao {
  134. return &BaseAccountDao{M: d.M.Option(option)}
  135. }
  136. // OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers
  137. // the data and where attributes for empty values.
  138. func (d *BaseAccountDao) OmitEmpty() *BaseAccountDao {
  139. return &BaseAccountDao{M: d.M.OmitEmpty()}
  140. }
  141. // Filter marks filtering the fields which does not exist in the fields of the operated table.
  142. func (d *BaseAccountDao) Filter() *BaseAccountDao {
  143. return &BaseAccountDao{M: d.M.Filter()}
  144. }
  145. // Where sets the condition statement for the model. The parameter <where> can be type of
  146. // string/map/gmap/slice/struct/*struct, etc. Note that, if it's called more than one times,
  147. // multiple conditions will be joined into where statement using "AND".
  148. // Eg:
  149. // Where("uid=10000")
  150. // Where("uid", 10000)
  151. // Where("money>? AND name like ?", 99999, "vip_%")
  152. // Where("uid", 1).Where("name", "john")
  153. // Where("status IN (?)", g.Slice{1,2,3})
  154. // Where("age IN(?,?)", 18, 50)
  155. // Where(User{ Id : 1, UserName : "john"})
  156. func (d *BaseAccountDao) Where(where interface{}, args ...interface{}) *BaseAccountDao {
  157. return &BaseAccountDao{M: d.M.Where(where, args...)}
  158. }
  159. // WherePri does the same logic as M.Where except that if the parameter <where>
  160. // is a single condition like int/string/float/slice, it treats the condition as the primary
  161. // key value. That is, if primary key is "id" and given <where> parameter as "123", the
  162. // WherePri function treats the condition as "id=123", but M.Where treats the condition
  163. // as string "123".
  164. func (d *BaseAccountDao) WherePri(where interface{}, args ...interface{}) *BaseAccountDao {
  165. return &BaseAccountDao{M: d.M.WherePri(where, args...)}
  166. }
  167. // And adds "AND" condition to the where statement.
  168. func (d *BaseAccountDao) And(where interface{}, args ...interface{}) *BaseAccountDao {
  169. return &BaseAccountDao{M: d.M.And(where, args...)}
  170. }
  171. // Or adds "OR" condition to the where statement.
  172. func (d *BaseAccountDao) Or(where interface{}, args ...interface{}) *BaseAccountDao {
  173. return &BaseAccountDao{M: d.M.Or(where, args...)}
  174. }
  175. // Group sets the "GROUP BY" statement for the model.
  176. func (d *BaseAccountDao) Group(groupBy string) *BaseAccountDao {
  177. return &BaseAccountDao{M: d.M.Group(groupBy)}
  178. }
  179. // Order sets the "ORDER BY" statement for the model.
  180. func (d *BaseAccountDao) Order(orderBy ...string) *BaseAccountDao {
  181. return &BaseAccountDao{M: d.M.Order(orderBy...)}
  182. }
  183. // Limit sets the "LIMIT" statement for the model.
  184. // The parameter <limit> can be either one or two number, if passed two number is passed,
  185. // it then sets "LIMIT limit[0],limit[1]" statement for the model, or else it sets "LIMIT limit[0]"
  186. // statement.
  187. func (d *BaseAccountDao) Limit(limit ...int) *BaseAccountDao {
  188. return &BaseAccountDao{M: d.M.Limit(limit...)}
  189. }
  190. // Offset sets the "OFFSET" statement for the model.
  191. // It only makes sense for some databases like SQLServer, PostgreSQL, etc.
  192. func (d *BaseAccountDao) Offset(offset int) *BaseAccountDao {
  193. return &BaseAccountDao{M: d.M.Offset(offset)}
  194. }
  195. // Page sets the paging number for the model.
  196. // The parameter <page> is started from 1 for paging.
  197. // Note that, it differs that the Limit function start from 0 for "LIMIT" statement.
  198. func (d *BaseAccountDao) Page(page, limit int) *BaseAccountDao {
  199. return &BaseAccountDao{M: d.M.Page(page, limit)}
  200. }
  201. // Batch sets the batch operation number for the model.
  202. func (d *BaseAccountDao) Batch(batch int) *BaseAccountDao {
  203. return &BaseAccountDao{M: d.M.Batch(batch)}
  204. }
  205. // Cache sets the cache feature for the model. It caches the result of the sql, which means
  206. // if there's another same sql request, it just reads and returns the result from cache, it
  207. // but not committed and executed into the database.
  208. //
  209. // If the parameter <duration> < 0, which means it clear the cache with given <name>.
  210. // If the parameter <duration> = 0, which means it never expires.
  211. // If the parameter <duration> > 0, which means it expires after <duration>.
  212. //
  213. // The optional parameter <name> is used to bind a name to the cache, which means you can later
  214. // control the cache like changing the <duration> or clearing the cache with specified <name>.
  215. //
  216. // Note that, the cache feature is disabled if the model is operating on a transaction.
  217. func (d *BaseAccountDao) Cache(duration time.Duration, name ...string) *BaseAccountDao {
  218. return &BaseAccountDao{M: d.M.Cache(duration, name...)}
  219. }
  220. // Data sets the operation data for the model.
  221. // The parameter <data> can be type of string/map/gmap/slice/struct/*struct, etc.
  222. // Eg:
  223. // Data("uid=10000")
  224. // Data("uid", 10000)
  225. // Data(g.Map{"uid": 10000, "name":"john"})
  226. // Data(g.Slice{g.Map{"uid": 10000, "name":"john"}, g.Map{"uid": 20000, "name":"smith"})
  227. func (d *BaseAccountDao) Data(data ...interface{}) *BaseAccountDao {
  228. return &BaseAccountDao{M: d.M.Data(data...)}
  229. }
  230. // All does "SELECT FROM ..." statement for the model.
  231. // It retrieves the records from table and returns the result as []*model.BaseAccount.
  232. // It returns nil if there's no record retrieved with the given conditions from table.
  233. //
  234. // The optional parameter <where> is the same as the parameter of M.Where function,
  235. // see M.Where.
  236. func (d *BaseAccountDao) All(where ...interface{}) ([]*model2.BaseAccount, error) {
  237. all, err := d.M.All(where...)
  238. if err != nil {
  239. return nil, err
  240. }
  241. var entities []*model2.BaseAccount
  242. if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
  243. return nil, err
  244. }
  245. return entities, nil
  246. }
  247. // One retrieves one record from table and returns the result as *model.BaseAccount.
  248. // It returns nil if there's no record retrieved with the given conditions from table.
  249. //
  250. // The optional parameter <where> is the same as the parameter of M.Where function,
  251. // see M.Where.
  252. func (d *BaseAccountDao) One(where ...interface{}) (*model2.BaseAccount, error) {
  253. one, err := d.M.One(where...)
  254. if err != nil {
  255. return nil, err
  256. }
  257. var entity *model2.BaseAccount
  258. if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
  259. return nil, err
  260. }
  261. return entity, nil
  262. }
  263. // FindOne retrieves and returns a single Record by M.WherePri and M.One.
  264. // Also see M.WherePri and M.One.
  265. func (d *BaseAccountDao) FindOne(where ...interface{}) (*model2.BaseAccount, error) {
  266. one, err := d.M.FindOne(where...)
  267. if err != nil {
  268. return nil, err
  269. }
  270. var entity *model2.BaseAccount
  271. if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
  272. return nil, err
  273. }
  274. return entity, nil
  275. }
  276. // FindAll retrieves and returns Result by by M.WherePri and M.All.
  277. // Also see M.WherePri and M.All.
  278. func (d *BaseAccountDao) FindAll(where ...interface{}) ([]*model2.BaseAccount, error) {
  279. all, err := d.M.FindAll(where...)
  280. if err != nil {
  281. return nil, err
  282. }
  283. var entities []*model2.BaseAccount
  284. if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
  285. return nil, err
  286. }
  287. return entities, nil
  288. }
  289. // Struct retrieves one record from table and converts it into given struct.
  290. // The parameter <pointer> should be type of *struct/**struct. If type **struct is given,
  291. // it can create the struct internally during converting.
  292. //
  293. // The optional parameter <where> is the same as the parameter of Model.Where function,
  294. // see Model.Where.
  295. //
  296. // Note that it returns sql.ErrNoRows if there's no record retrieved with the given conditions
  297. // from table and <pointer> is not nil.
  298. //
  299. // Eg:
  300. // user := new(User)
  301. // err := dao.User.Where("id", 1).Struct(user)
  302. //
  303. // user := (*User)(nil)
  304. // err := dao.User.Where("id", 1).Struct(&user)
  305. func (d *BaseAccountDao) Struct(pointer interface{}, where ...interface{}) error {
  306. return d.M.Struct(pointer, where...)
  307. }
  308. // Structs retrieves records from table and converts them into given struct slice.
  309. // The parameter <pointer> should be type of *[]struct/*[]*struct. It can create and fill the struct
  310. // slice internally during converting.
  311. //
  312. // The optional parameter <where> is the same as the parameter of Model.Where function,
  313. // see Model.Where.
  314. //
  315. // Note that it returns sql.ErrNoRows if there's no record retrieved with the given conditions
  316. // from table and <pointer> is not empty.
  317. //
  318. // Eg:
  319. // users := ([]User)(nil)
  320. // err := dao.User.Structs(&users)
  321. //
  322. // users := ([]*User)(nil)
  323. // err := dao.User.Structs(&users)
  324. func (d *BaseAccountDao) Structs(pointer interface{}, where ...interface{}) error {
  325. return d.M.Structs(pointer, where...)
  326. }
  327. // Scan automatically calls Struct or Structs function according to the type of parameter <pointer>.
  328. // It calls function Struct if <pointer> is type of *struct/**struct.
  329. // It calls function Structs if <pointer> is type of *[]struct/*[]*struct.
  330. //
  331. // The optional parameter <where> is the same as the parameter of Model.Where function,
  332. // see Model.Where.
  333. //
  334. // Note that it returns sql.ErrNoRows if there's no record retrieved and given pointer is not empty or nil.
  335. //
  336. // Eg:
  337. // user := new(User)
  338. // err := dao.User.Where("id", 1).Scan(user)
  339. //
  340. // user := (*User)(nil)
  341. // err := dao.User.Where("id", 1).Scan(&user)
  342. //
  343. // users := ([]User)(nil)
  344. // err := dao.User.Scan(&users)
  345. //
  346. // users := ([]*User)(nil)
  347. // err := dao.User.Scan(&users)
  348. func (d *BaseAccountDao) Scan(pointer interface{}, where ...interface{}) error {
  349. return d.M.Scan(pointer, where...)
  350. }
  351. // Chunk iterates the table with given size and callback function.
  352. func (d *BaseAccountDao) Chunk(limit int, callback func(entities []*model2.BaseAccount, err error) bool) {
  353. d.M.Chunk(limit, func(result gdb.Result, err error) bool {
  354. var entities []*model2.BaseAccount
  355. err = result.Structs(&entities)
  356. if err == sql.ErrNoRows {
  357. return false
  358. }
  359. return callback(entities, err)
  360. })
  361. }
  362. // LockUpdate sets the lock for update for current operation.
  363. func (d *BaseAccountDao) LockUpdate() *BaseAccountDao {
  364. return &BaseAccountDao{M: d.M.LockUpdate()}
  365. }
  366. // LockShared sets the lock in share mode for current operation.
  367. func (d *BaseAccountDao) LockShared() *BaseAccountDao {
  368. return &BaseAccountDao{M: d.M.LockShared()}
  369. }
  370. // Unscoped enables/disables the soft deleting feature.
  371. func (d *BaseAccountDao) Unscoped() *BaseAccountDao {
  372. return &BaseAccountDao{M: d.M.Unscoped()}
  373. }