gen.go 4.9 KB

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