base_district.go 16 KB

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