gen.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // Code generated by gorm.io/gen. DO NOT EDIT.
  2. // Code generated by gorm.io/gen. DO NOT EDIT.
  3. // Code generated by gorm.io/gen. DO NOT EDIT.
  4. package query
  5. import (
  6. "context"
  7. "database/sql"
  8. "gorm.io/gorm"
  9. "gorm.io/gen"
  10. "gorm.io/plugin/dbresolver"
  11. )
  12. func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
  13. return &Query{
  14. db: db,
  15. AdLog: newAdLog(db, opts...),
  16. GuideLog: newGuideLog(db, opts...),
  17. LoginLog: newLoginLog(db, opts...),
  18. OnlineDurationLog: newOnlineDurationLog(db, opts...),
  19. }
  20. }
  21. type Query struct {
  22. db *gorm.DB
  23. AdLog adLog
  24. GuideLog guideLog
  25. LoginLog loginLog
  26. OnlineDurationLog onlineDurationLog
  27. }
  28. func (q *Query) Available() bool { return q.db != nil }
  29. func (q *Query) clone(db *gorm.DB) *Query {
  30. return &Query{
  31. db: db,
  32. AdLog: q.AdLog.clone(db),
  33. GuideLog: q.GuideLog.clone(db),
  34. LoginLog: q.LoginLog.clone(db),
  35. OnlineDurationLog: q.OnlineDurationLog.clone(db),
  36. }
  37. }
  38. func (q *Query) ReadDB() *Query {
  39. return q.ReplaceDB(q.db.Clauses(dbresolver.Read))
  40. }
  41. func (q *Query) WriteDB() *Query {
  42. return q.ReplaceDB(q.db.Clauses(dbresolver.Write))
  43. }
  44. func (q *Query) ReplaceDB(db *gorm.DB) *Query {
  45. return &Query{
  46. db: db,
  47. AdLog: q.AdLog.replaceDB(db),
  48. GuideLog: q.GuideLog.replaceDB(db),
  49. LoginLog: q.LoginLog.replaceDB(db),
  50. OnlineDurationLog: q.OnlineDurationLog.replaceDB(db),
  51. }
  52. }
  53. type queryCtx struct {
  54. AdLog *adLogDo
  55. GuideLog *guideLogDo
  56. LoginLog *loginLogDo
  57. OnlineDurationLog *onlineDurationLogDo
  58. }
  59. func (q *Query) WithContext(ctx context.Context) *queryCtx {
  60. return &queryCtx{
  61. AdLog: q.AdLog.WithContext(ctx),
  62. GuideLog: q.GuideLog.WithContext(ctx),
  63. LoginLog: q.LoginLog.WithContext(ctx),
  64. OnlineDurationLog: q.OnlineDurationLog.WithContext(ctx),
  65. }
  66. }
  67. func (q *Query) Transaction(fc func(tx *Query) error, opts ...*sql.TxOptions) error {
  68. return q.db.Transaction(func(tx *gorm.DB) error { return fc(q.clone(tx)) }, opts...)
  69. }
  70. func (q *Query) Begin(opts ...*sql.TxOptions) *QueryTx {
  71. tx := q.db.Begin(opts...)
  72. return &QueryTx{Query: q.clone(tx), Error: tx.Error}
  73. }
  74. type QueryTx struct {
  75. *Query
  76. Error error
  77. }
  78. func (q *QueryTx) Commit() error {
  79. return q.db.Commit().Error
  80. }
  81. func (q *QueryTx) Rollback() error {
  82. return q.db.Rollback().Error
  83. }
  84. func (q *QueryTx) SavePoint(name string) error {
  85. return q.db.SavePoint(name).Error
  86. }
  87. func (q *QueryTx) RollbackTo(name string) error {
  88. return q.db.RollbackTo(name).Error
  89. }