gen.go 5.6 KB

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