gen.go 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. var (
  13. Q = new(Query)
  14. AcmeUser *acmeUser
  15. Auth *auth
  16. AuthToken *authToken
  17. BanIP *banIP
  18. Cert *cert
  19. ChatGPTLog *chatGPTLog
  20. Config *config
  21. ConfigBackup *configBackup
  22. DnsCredential *dnsCredential
  23. Environment *environment
  24. Notification *notification
  25. Site *site
  26. Stream *stream
  27. )
  28. func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
  29. *Q = *Use(db, opts...)
  30. AcmeUser = &Q.AcmeUser
  31. Auth = &Q.Auth
  32. AuthToken = &Q.AuthToken
  33. BanIP = &Q.BanIP
  34. Cert = &Q.Cert
  35. ChatGPTLog = &Q.ChatGPTLog
  36. Config = &Q.Config
  37. ConfigBackup = &Q.ConfigBackup
  38. DnsCredential = &Q.DnsCredential
  39. Environment = &Q.Environment
  40. Notification = &Q.Notification
  41. Site = &Q.Site
  42. Stream = &Q.Stream
  43. }
  44. func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
  45. return &Query{
  46. db: db,
  47. AcmeUser: newAcmeUser(db, opts...),
  48. Auth: newAuth(db, opts...),
  49. AuthToken: newAuthToken(db, opts...),
  50. BanIP: newBanIP(db, opts...),
  51. Cert: newCert(db, opts...),
  52. ChatGPTLog: newChatGPTLog(db, opts...),
  53. Config: newConfig(db, opts...),
  54. ConfigBackup: newConfigBackup(db, opts...),
  55. DnsCredential: newDnsCredential(db, opts...),
  56. Environment: newEnvironment(db, opts...),
  57. Notification: newNotification(db, opts...),
  58. Site: newSite(db, opts...),
  59. Stream: newStream(db, opts...),
  60. }
  61. }
  62. type Query struct {
  63. db *gorm.DB
  64. AcmeUser acmeUser
  65. Auth auth
  66. AuthToken authToken
  67. BanIP banIP
  68. Cert cert
  69. ChatGPTLog chatGPTLog
  70. Config config
  71. ConfigBackup configBackup
  72. DnsCredential dnsCredential
  73. Environment environment
  74. Notification notification
  75. Site site
  76. Stream stream
  77. }
  78. func (q *Query) Available() bool { return q.db != nil }
  79. func (q *Query) clone(db *gorm.DB) *Query {
  80. return &Query{
  81. db: db,
  82. AcmeUser: q.AcmeUser.clone(db),
  83. Auth: q.Auth.clone(db),
  84. AuthToken: q.AuthToken.clone(db),
  85. BanIP: q.BanIP.clone(db),
  86. Cert: q.Cert.clone(db),
  87. ChatGPTLog: q.ChatGPTLog.clone(db),
  88. Config: q.Config.clone(db),
  89. ConfigBackup: q.ConfigBackup.clone(db),
  90. DnsCredential: q.DnsCredential.clone(db),
  91. Environment: q.Environment.clone(db),
  92. Notification: q.Notification.clone(db),
  93. Site: q.Site.clone(db),
  94. Stream: q.Stream.clone(db),
  95. }
  96. }
  97. func (q *Query) ReadDB() *Query {
  98. return q.ReplaceDB(q.db.Clauses(dbresolver.Read))
  99. }
  100. func (q *Query) WriteDB() *Query {
  101. return q.ReplaceDB(q.db.Clauses(dbresolver.Write))
  102. }
  103. func (q *Query) ReplaceDB(db *gorm.DB) *Query {
  104. return &Query{
  105. db: db,
  106. AcmeUser: q.AcmeUser.replaceDB(db),
  107. Auth: q.Auth.replaceDB(db),
  108. AuthToken: q.AuthToken.replaceDB(db),
  109. BanIP: q.BanIP.replaceDB(db),
  110. Cert: q.Cert.replaceDB(db),
  111. ChatGPTLog: q.ChatGPTLog.replaceDB(db),
  112. Config: q.Config.replaceDB(db),
  113. ConfigBackup: q.ConfigBackup.replaceDB(db),
  114. DnsCredential: q.DnsCredential.replaceDB(db),
  115. Environment: q.Environment.replaceDB(db),
  116. Notification: q.Notification.replaceDB(db),
  117. Site: q.Site.replaceDB(db),
  118. Stream: q.Stream.replaceDB(db),
  119. }
  120. }
  121. type queryCtx struct {
  122. AcmeUser *acmeUserDo
  123. Auth *authDo
  124. AuthToken *authTokenDo
  125. BanIP *banIPDo
  126. Cert *certDo
  127. ChatGPTLog *chatGPTLogDo
  128. Config *configDo
  129. ConfigBackup *configBackupDo
  130. DnsCredential *dnsCredentialDo
  131. Environment *environmentDo
  132. Notification *notificationDo
  133. Site *siteDo
  134. Stream *streamDo
  135. }
  136. func (q *Query) WithContext(ctx context.Context) *queryCtx {
  137. return &queryCtx{
  138. AcmeUser: q.AcmeUser.WithContext(ctx),
  139. Auth: q.Auth.WithContext(ctx),
  140. AuthToken: q.AuthToken.WithContext(ctx),
  141. BanIP: q.BanIP.WithContext(ctx),
  142. Cert: q.Cert.WithContext(ctx),
  143. ChatGPTLog: q.ChatGPTLog.WithContext(ctx),
  144. Config: q.Config.WithContext(ctx),
  145. ConfigBackup: q.ConfigBackup.WithContext(ctx),
  146. DnsCredential: q.DnsCredential.WithContext(ctx),
  147. Environment: q.Environment.WithContext(ctx),
  148. Notification: q.Notification.WithContext(ctx),
  149. Site: q.Site.WithContext(ctx),
  150. Stream: q.Stream.WithContext(ctx),
  151. }
  152. }
  153. func (q *Query) Transaction(fc func(tx *Query) error, opts ...*sql.TxOptions) error {
  154. return q.db.Transaction(func(tx *gorm.DB) error { return fc(q.clone(tx)) }, opts...)
  155. }
  156. func (q *Query) Begin(opts ...*sql.TxOptions) *QueryTx {
  157. tx := q.db.Begin(opts...)
  158. return &QueryTx{Query: q.clone(tx), Error: tx.Error}
  159. }
  160. type QueryTx struct {
  161. *Query
  162. Error error
  163. }
  164. func (q *QueryTx) Commit() error {
  165. return q.db.Commit().Error
  166. }
  167. func (q *QueryTx) Rollback() error {
  168. return q.db.Rollback().Error
  169. }
  170. func (q *QueryTx) SavePoint(name string) error {
  171. return q.db.SavePoint(name).Error
  172. }
  173. func (q *QueryTx) RollbackTo(name string) error {
  174. return q.db.RollbackTo(name).Error
  175. }