gen.go 4.1 KB

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