gen.go 5.4 KB

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