gen.go 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. AutoBackup *autoBackup
  17. BanIP *banIP
  18. Cert *cert
  19. ChatGPTLog *chatGPTLog
  20. Config *config
  21. ConfigBackup *configBackup
  22. DnsCredential *dnsCredential
  23. ExternalNotify *externalNotify
  24. Namespace *namespace
  25. Node *node
  26. Notification *notification
  27. Passkey *passkey
  28. Site *site
  29. SiteConfig *siteConfig
  30. Stream *stream
  31. User *user
  32. )
  33. func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
  34. *Q = *Use(db, opts...)
  35. AcmeUser = &Q.AcmeUser
  36. AuthToken = &Q.AuthToken
  37. AutoBackup = &Q.AutoBackup
  38. BanIP = &Q.BanIP
  39. Cert = &Q.Cert
  40. ChatGPTLog = &Q.ChatGPTLog
  41. Config = &Q.Config
  42. ConfigBackup = &Q.ConfigBackup
  43. DnsCredential = &Q.DnsCredential
  44. ExternalNotify = &Q.ExternalNotify
  45. Namespace = &Q.Namespace
  46. Node = &Q.Node
  47. Notification = &Q.Notification
  48. Passkey = &Q.Passkey
  49. Site = &Q.Site
  50. SiteConfig = &Q.SiteConfig
  51. Stream = &Q.Stream
  52. User = &Q.User
  53. }
  54. func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
  55. return &Query{
  56. db: db,
  57. AcmeUser: newAcmeUser(db, opts...),
  58. AuthToken: newAuthToken(db, opts...),
  59. AutoBackup: newAutoBackup(db, opts...),
  60. BanIP: newBanIP(db, opts...),
  61. Cert: newCert(db, opts...),
  62. ChatGPTLog: newChatGPTLog(db, opts...),
  63. Config: newConfig(db, opts...),
  64. ConfigBackup: newConfigBackup(db, opts...),
  65. DnsCredential: newDnsCredential(db, opts...),
  66. ExternalNotify: newExternalNotify(db, opts...),
  67. Namespace: newNamespace(db, opts...),
  68. Node: newNode(db, opts...),
  69. Notification: newNotification(db, opts...),
  70. Passkey: newPasskey(db, opts...),
  71. Site: newSite(db, opts...),
  72. SiteConfig: newSiteConfig(db, opts...),
  73. Stream: newStream(db, opts...),
  74. User: newUser(db, opts...),
  75. }
  76. }
  77. type Query struct {
  78. db *gorm.DB
  79. AcmeUser acmeUser
  80. AuthToken authToken
  81. AutoBackup autoBackup
  82. BanIP banIP
  83. Cert cert
  84. ChatGPTLog chatGPTLog
  85. Config config
  86. ConfigBackup configBackup
  87. DnsCredential dnsCredential
  88. ExternalNotify externalNotify
  89. Namespace namespace
  90. Node node
  91. Notification notification
  92. Passkey passkey
  93. Site site
  94. SiteConfig siteConfig
  95. Stream stream
  96. User user
  97. }
  98. func (q *Query) Available() bool { return q.db != nil }
  99. func (q *Query) clone(db *gorm.DB) *Query {
  100. return &Query{
  101. db: db,
  102. AcmeUser: q.AcmeUser.clone(db),
  103. AuthToken: q.AuthToken.clone(db),
  104. AutoBackup: q.AutoBackup.clone(db),
  105. BanIP: q.BanIP.clone(db),
  106. Cert: q.Cert.clone(db),
  107. ChatGPTLog: q.ChatGPTLog.clone(db),
  108. Config: q.Config.clone(db),
  109. ConfigBackup: q.ConfigBackup.clone(db),
  110. DnsCredential: q.DnsCredential.clone(db),
  111. ExternalNotify: q.ExternalNotify.clone(db),
  112. Namespace: q.Namespace.clone(db),
  113. Node: q.Node.clone(db),
  114. Notification: q.Notification.clone(db),
  115. Passkey: q.Passkey.clone(db),
  116. Site: q.Site.clone(db),
  117. SiteConfig: q.SiteConfig.clone(db),
  118. Stream: q.Stream.clone(db),
  119. User: q.User.clone(db),
  120. }
  121. }
  122. func (q *Query) ReadDB() *Query {
  123. return q.ReplaceDB(q.db.Clauses(dbresolver.Read))
  124. }
  125. func (q *Query) WriteDB() *Query {
  126. return q.ReplaceDB(q.db.Clauses(dbresolver.Write))
  127. }
  128. func (q *Query) ReplaceDB(db *gorm.DB) *Query {
  129. return &Query{
  130. db: db,
  131. AcmeUser: q.AcmeUser.replaceDB(db),
  132. AuthToken: q.AuthToken.replaceDB(db),
  133. AutoBackup: q.AutoBackup.replaceDB(db),
  134. BanIP: q.BanIP.replaceDB(db),
  135. Cert: q.Cert.replaceDB(db),
  136. ChatGPTLog: q.ChatGPTLog.replaceDB(db),
  137. Config: q.Config.replaceDB(db),
  138. ConfigBackup: q.ConfigBackup.replaceDB(db),
  139. DnsCredential: q.DnsCredential.replaceDB(db),
  140. ExternalNotify: q.ExternalNotify.replaceDB(db),
  141. Namespace: q.Namespace.replaceDB(db),
  142. Node: q.Node.replaceDB(db),
  143. Notification: q.Notification.replaceDB(db),
  144. Passkey: q.Passkey.replaceDB(db),
  145. Site: q.Site.replaceDB(db),
  146. SiteConfig: q.SiteConfig.replaceDB(db),
  147. Stream: q.Stream.replaceDB(db),
  148. User: q.User.replaceDB(db),
  149. }
  150. }
  151. type queryCtx struct {
  152. AcmeUser *acmeUserDo
  153. AuthToken *authTokenDo
  154. AutoBackup *autoBackupDo
  155. BanIP *banIPDo
  156. Cert *certDo
  157. ChatGPTLog *chatGPTLogDo
  158. Config *configDo
  159. ConfigBackup *configBackupDo
  160. DnsCredential *dnsCredentialDo
  161. ExternalNotify *externalNotifyDo
  162. Namespace *namespaceDo
  163. Node *nodeDo
  164. Notification *notificationDo
  165. Passkey *passkeyDo
  166. Site *siteDo
  167. SiteConfig *siteConfigDo
  168. Stream *streamDo
  169. User *userDo
  170. }
  171. func (q *Query) WithContext(ctx context.Context) *queryCtx {
  172. return &queryCtx{
  173. AcmeUser: q.AcmeUser.WithContext(ctx),
  174. AuthToken: q.AuthToken.WithContext(ctx),
  175. AutoBackup: q.AutoBackup.WithContext(ctx),
  176. BanIP: q.BanIP.WithContext(ctx),
  177. Cert: q.Cert.WithContext(ctx),
  178. ChatGPTLog: q.ChatGPTLog.WithContext(ctx),
  179. Config: q.Config.WithContext(ctx),
  180. ConfigBackup: q.ConfigBackup.WithContext(ctx),
  181. DnsCredential: q.DnsCredential.WithContext(ctx),
  182. ExternalNotify: q.ExternalNotify.WithContext(ctx),
  183. Namespace: q.Namespace.WithContext(ctx),
  184. Node: q.Node.WithContext(ctx),
  185. Notification: q.Notification.WithContext(ctx),
  186. Passkey: q.Passkey.WithContext(ctx),
  187. Site: q.Site.WithContext(ctx),
  188. SiteConfig: q.SiteConfig.WithContext(ctx),
  189. Stream: q.Stream.WithContext(ctx),
  190. User: q.User.WithContext(ctx),
  191. }
  192. }
  193. func (q *Query) Transaction(fc func(tx *Query) error, opts ...*sql.TxOptions) error {
  194. return q.db.Transaction(func(tx *gorm.DB) error { return fc(q.clone(tx)) }, opts...)
  195. }
  196. func (q *Query) Begin(opts ...*sql.TxOptions) *QueryTx {
  197. tx := q.db.Begin(opts...)
  198. return &QueryTx{Query: q.clone(tx), Error: tx.Error}
  199. }
  200. type QueryTx struct {
  201. *Query
  202. Error error
  203. }
  204. func (q *QueryTx) Commit() error {
  205. return q.db.Commit().Error
  206. }
  207. func (q *QueryTx) Rollback() error {
  208. return q.db.Rollback().Error
  209. }
  210. func (q *QueryTx) SavePoint(name string) error {
  211. return q.db.SavePoint(name).Error
  212. }
  213. func (q *QueryTx) RollbackTo(name string) error {
  214. return q.db.RollbackTo(name).Error
  215. }