gen.go 4.4 KB

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