certs.gen.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  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. "strings"
  8. "gorm.io/gorm"
  9. "gorm.io/gorm/clause"
  10. "gorm.io/gorm/schema"
  11. "gorm.io/gen"
  12. "gorm.io/gen/field"
  13. "gorm.io/plugin/dbresolver"
  14. "github.com/0xJacky/Nginx-UI/model"
  15. )
  16. func newCert(db *gorm.DB, opts ...gen.DOOption) cert {
  17. _cert := cert{}
  18. _cert.certDo.UseDB(db, opts...)
  19. _cert.certDo.UseModel(&model.Cert{})
  20. tableName := _cert.certDo.TableName()
  21. _cert.ALL = field.NewAsterisk(tableName)
  22. _cert.ID = field.NewUint64(tableName, "id")
  23. _cert.CreatedAt = field.NewTime(tableName, "created_at")
  24. _cert.UpdatedAt = field.NewTime(tableName, "updated_at")
  25. _cert.DeletedAt = field.NewField(tableName, "deleted_at")
  26. _cert.Name = field.NewString(tableName, "name")
  27. _cert.Domains = field.NewField(tableName, "domains")
  28. _cert.Filename = field.NewString(tableName, "filename")
  29. _cert.SSLCertificatePath = field.NewString(tableName, "ssl_certificate_path")
  30. _cert.SSLCertificateKeyPath = field.NewString(tableName, "ssl_certificate_key_path")
  31. _cert.AutoCert = field.NewInt(tableName, "auto_cert")
  32. _cert.ChallengeMethod = field.NewString(tableName, "challenge_method")
  33. _cert.DnsCredentialID = field.NewUint64(tableName, "dns_credential_id")
  34. _cert.ACMEUserID = field.NewUint64(tableName, "acme_user_id")
  35. _cert.KeyType = field.NewString(tableName, "key_type")
  36. _cert.Log = field.NewString(tableName, "log")
  37. _cert.Resource = field.NewField(tableName, "resource")
  38. _cert.SyncNodeIds = field.NewField(tableName, "sync_node_ids")
  39. _cert.MustStaple = field.NewBool(tableName, "must_staple")
  40. _cert.LegoDisableCNAMESupport = field.NewBool(tableName, "lego_disable_cname_support")
  41. _cert.RevokeOld = field.NewBool(tableName, "revoke_old")
  42. _cert.DnsCredential = certBelongsToDnsCredential{
  43. db: db.Session(&gorm.Session{}),
  44. RelationField: field.NewRelation("DnsCredential", "model.DnsCredential"),
  45. }
  46. _cert.ACMEUser = certBelongsToACMEUser{
  47. db: db.Session(&gorm.Session{}),
  48. RelationField: field.NewRelation("ACMEUser", "model.AcmeUser"),
  49. }
  50. _cert.fillFieldMap()
  51. return _cert
  52. }
  53. type cert struct {
  54. certDo
  55. ALL field.Asterisk
  56. ID field.Uint64
  57. CreatedAt field.Time
  58. UpdatedAt field.Time
  59. DeletedAt field.Field
  60. Name field.String
  61. Domains field.Field
  62. Filename field.String
  63. SSLCertificatePath field.String
  64. SSLCertificateKeyPath field.String
  65. AutoCert field.Int
  66. ChallengeMethod field.String
  67. DnsCredentialID field.Uint64
  68. ACMEUserID field.Uint64
  69. KeyType field.String
  70. Log field.String
  71. Resource field.Field
  72. SyncNodeIds field.Field
  73. MustStaple field.Bool
  74. LegoDisableCNAMESupport field.Bool
  75. RevokeOld field.Bool
  76. DnsCredential certBelongsToDnsCredential
  77. ACMEUser certBelongsToACMEUser
  78. fieldMap map[string]field.Expr
  79. }
  80. func (c cert) Table(newTableName string) *cert {
  81. c.certDo.UseTable(newTableName)
  82. return c.updateTableName(newTableName)
  83. }
  84. func (c cert) As(alias string) *cert {
  85. c.certDo.DO = *(c.certDo.As(alias).(*gen.DO))
  86. return c.updateTableName(alias)
  87. }
  88. func (c *cert) updateTableName(table string) *cert {
  89. c.ALL = field.NewAsterisk(table)
  90. c.ID = field.NewUint64(table, "id")
  91. c.CreatedAt = field.NewTime(table, "created_at")
  92. c.UpdatedAt = field.NewTime(table, "updated_at")
  93. c.DeletedAt = field.NewField(table, "deleted_at")
  94. c.Name = field.NewString(table, "name")
  95. c.Domains = field.NewField(table, "domains")
  96. c.Filename = field.NewString(table, "filename")
  97. c.SSLCertificatePath = field.NewString(table, "ssl_certificate_path")
  98. c.SSLCertificateKeyPath = field.NewString(table, "ssl_certificate_key_path")
  99. c.AutoCert = field.NewInt(table, "auto_cert")
  100. c.ChallengeMethod = field.NewString(table, "challenge_method")
  101. c.DnsCredentialID = field.NewUint64(table, "dns_credential_id")
  102. c.ACMEUserID = field.NewUint64(table, "acme_user_id")
  103. c.KeyType = field.NewString(table, "key_type")
  104. c.Log = field.NewString(table, "log")
  105. c.Resource = field.NewField(table, "resource")
  106. c.SyncNodeIds = field.NewField(table, "sync_node_ids")
  107. c.MustStaple = field.NewBool(table, "must_staple")
  108. c.LegoDisableCNAMESupport = field.NewBool(table, "lego_disable_cname_support")
  109. c.RevokeOld = field.NewBool(table, "revoke_old")
  110. c.fillFieldMap()
  111. return c
  112. }
  113. func (c *cert) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
  114. _f, ok := c.fieldMap[fieldName]
  115. if !ok || _f == nil {
  116. return nil, false
  117. }
  118. _oe, ok := _f.(field.OrderExpr)
  119. return _oe, ok
  120. }
  121. func (c *cert) fillFieldMap() {
  122. c.fieldMap = make(map[string]field.Expr, 22)
  123. c.fieldMap["id"] = c.ID
  124. c.fieldMap["created_at"] = c.CreatedAt
  125. c.fieldMap["updated_at"] = c.UpdatedAt
  126. c.fieldMap["deleted_at"] = c.DeletedAt
  127. c.fieldMap["name"] = c.Name
  128. c.fieldMap["domains"] = c.Domains
  129. c.fieldMap["filename"] = c.Filename
  130. c.fieldMap["ssl_certificate_path"] = c.SSLCertificatePath
  131. c.fieldMap["ssl_certificate_key_path"] = c.SSLCertificateKeyPath
  132. c.fieldMap["auto_cert"] = c.AutoCert
  133. c.fieldMap["challenge_method"] = c.ChallengeMethod
  134. c.fieldMap["dns_credential_id"] = c.DnsCredentialID
  135. c.fieldMap["acme_user_id"] = c.ACMEUserID
  136. c.fieldMap["key_type"] = c.KeyType
  137. c.fieldMap["log"] = c.Log
  138. c.fieldMap["resource"] = c.Resource
  139. c.fieldMap["sync_node_ids"] = c.SyncNodeIds
  140. c.fieldMap["must_staple"] = c.MustStaple
  141. c.fieldMap["lego_disable_cname_support"] = c.LegoDisableCNAMESupport
  142. c.fieldMap["revoke_old"] = c.RevokeOld
  143. }
  144. func (c cert) clone(db *gorm.DB) cert {
  145. c.certDo.ReplaceConnPool(db.Statement.ConnPool)
  146. c.DnsCredential.db = db.Session(&gorm.Session{Initialized: true})
  147. c.DnsCredential.db.Statement.ConnPool = db.Statement.ConnPool
  148. c.ACMEUser.db = db.Session(&gorm.Session{Initialized: true})
  149. c.ACMEUser.db.Statement.ConnPool = db.Statement.ConnPool
  150. return c
  151. }
  152. func (c cert) replaceDB(db *gorm.DB) cert {
  153. c.certDo.ReplaceDB(db)
  154. c.DnsCredential.db = db.Session(&gorm.Session{})
  155. c.ACMEUser.db = db.Session(&gorm.Session{})
  156. return c
  157. }
  158. type certBelongsToDnsCredential struct {
  159. db *gorm.DB
  160. field.RelationField
  161. }
  162. func (a certBelongsToDnsCredential) Where(conds ...field.Expr) *certBelongsToDnsCredential {
  163. if len(conds) == 0 {
  164. return &a
  165. }
  166. exprs := make([]clause.Expression, 0, len(conds))
  167. for _, cond := range conds {
  168. exprs = append(exprs, cond.BeCond().(clause.Expression))
  169. }
  170. a.db = a.db.Clauses(clause.Where{Exprs: exprs})
  171. return &a
  172. }
  173. func (a certBelongsToDnsCredential) WithContext(ctx context.Context) *certBelongsToDnsCredential {
  174. a.db = a.db.WithContext(ctx)
  175. return &a
  176. }
  177. func (a certBelongsToDnsCredential) Session(session *gorm.Session) *certBelongsToDnsCredential {
  178. a.db = a.db.Session(session)
  179. return &a
  180. }
  181. func (a certBelongsToDnsCredential) Model(m *model.Cert) *certBelongsToDnsCredentialTx {
  182. return &certBelongsToDnsCredentialTx{a.db.Model(m).Association(a.Name())}
  183. }
  184. func (a certBelongsToDnsCredential) Unscoped() *certBelongsToDnsCredential {
  185. a.db = a.db.Unscoped()
  186. return &a
  187. }
  188. type certBelongsToDnsCredentialTx struct{ tx *gorm.Association }
  189. func (a certBelongsToDnsCredentialTx) Find() (result *model.DnsCredential, err error) {
  190. return result, a.tx.Find(&result)
  191. }
  192. func (a certBelongsToDnsCredentialTx) Append(values ...*model.DnsCredential) (err error) {
  193. targetValues := make([]interface{}, len(values))
  194. for i, v := range values {
  195. targetValues[i] = v
  196. }
  197. return a.tx.Append(targetValues...)
  198. }
  199. func (a certBelongsToDnsCredentialTx) Replace(values ...*model.DnsCredential) (err error) {
  200. targetValues := make([]interface{}, len(values))
  201. for i, v := range values {
  202. targetValues[i] = v
  203. }
  204. return a.tx.Replace(targetValues...)
  205. }
  206. func (a certBelongsToDnsCredentialTx) Delete(values ...*model.DnsCredential) (err error) {
  207. targetValues := make([]interface{}, len(values))
  208. for i, v := range values {
  209. targetValues[i] = v
  210. }
  211. return a.tx.Delete(targetValues...)
  212. }
  213. func (a certBelongsToDnsCredentialTx) Clear() error {
  214. return a.tx.Clear()
  215. }
  216. func (a certBelongsToDnsCredentialTx) Count() int64 {
  217. return a.tx.Count()
  218. }
  219. func (a certBelongsToDnsCredentialTx) Unscoped() *certBelongsToDnsCredentialTx {
  220. a.tx = a.tx.Unscoped()
  221. return &a
  222. }
  223. type certBelongsToACMEUser struct {
  224. db *gorm.DB
  225. field.RelationField
  226. }
  227. func (a certBelongsToACMEUser) Where(conds ...field.Expr) *certBelongsToACMEUser {
  228. if len(conds) == 0 {
  229. return &a
  230. }
  231. exprs := make([]clause.Expression, 0, len(conds))
  232. for _, cond := range conds {
  233. exprs = append(exprs, cond.BeCond().(clause.Expression))
  234. }
  235. a.db = a.db.Clauses(clause.Where{Exprs: exprs})
  236. return &a
  237. }
  238. func (a certBelongsToACMEUser) WithContext(ctx context.Context) *certBelongsToACMEUser {
  239. a.db = a.db.WithContext(ctx)
  240. return &a
  241. }
  242. func (a certBelongsToACMEUser) Session(session *gorm.Session) *certBelongsToACMEUser {
  243. a.db = a.db.Session(session)
  244. return &a
  245. }
  246. func (a certBelongsToACMEUser) Model(m *model.Cert) *certBelongsToACMEUserTx {
  247. return &certBelongsToACMEUserTx{a.db.Model(m).Association(a.Name())}
  248. }
  249. func (a certBelongsToACMEUser) Unscoped() *certBelongsToACMEUser {
  250. a.db = a.db.Unscoped()
  251. return &a
  252. }
  253. type certBelongsToACMEUserTx struct{ tx *gorm.Association }
  254. func (a certBelongsToACMEUserTx) Find() (result *model.AcmeUser, err error) {
  255. return result, a.tx.Find(&result)
  256. }
  257. func (a certBelongsToACMEUserTx) Append(values ...*model.AcmeUser) (err error) {
  258. targetValues := make([]interface{}, len(values))
  259. for i, v := range values {
  260. targetValues[i] = v
  261. }
  262. return a.tx.Append(targetValues...)
  263. }
  264. func (a certBelongsToACMEUserTx) Replace(values ...*model.AcmeUser) (err error) {
  265. targetValues := make([]interface{}, len(values))
  266. for i, v := range values {
  267. targetValues[i] = v
  268. }
  269. return a.tx.Replace(targetValues...)
  270. }
  271. func (a certBelongsToACMEUserTx) Delete(values ...*model.AcmeUser) (err error) {
  272. targetValues := make([]interface{}, len(values))
  273. for i, v := range values {
  274. targetValues[i] = v
  275. }
  276. return a.tx.Delete(targetValues...)
  277. }
  278. func (a certBelongsToACMEUserTx) Clear() error {
  279. return a.tx.Clear()
  280. }
  281. func (a certBelongsToACMEUserTx) Count() int64 {
  282. return a.tx.Count()
  283. }
  284. func (a certBelongsToACMEUserTx) Unscoped() *certBelongsToACMEUserTx {
  285. a.tx = a.tx.Unscoped()
  286. return &a
  287. }
  288. type certDo struct{ gen.DO }
  289. // FirstByID Where("id=@id")
  290. func (c certDo) FirstByID(id uint64) (result *model.Cert, err error) {
  291. var params []interface{}
  292. var generateSQL strings.Builder
  293. params = append(params, id)
  294. generateSQL.WriteString("id=? ")
  295. var executeSQL *gorm.DB
  296. executeSQL = c.UnderlyingDB().Where(generateSQL.String(), params...).Take(&result) // ignore_security_alert
  297. err = executeSQL.Error
  298. return
  299. }
  300. // DeleteByID update @@table set deleted_at=strftime('%Y-%m-%d %H:%M:%S','now') where id=@id
  301. func (c certDo) DeleteByID(id uint64) (err error) {
  302. var params []interface{}
  303. var generateSQL strings.Builder
  304. params = append(params, id)
  305. generateSQL.WriteString("update certs set deleted_at=strftime('%Y-%m-%d %H:%M:%S','now') where id=? ")
  306. var executeSQL *gorm.DB
  307. executeSQL = c.UnderlyingDB().Exec(generateSQL.String(), params...) // ignore_security_alert
  308. err = executeSQL.Error
  309. return
  310. }
  311. func (c certDo) Debug() *certDo {
  312. return c.withDO(c.DO.Debug())
  313. }
  314. func (c certDo) WithContext(ctx context.Context) *certDo {
  315. return c.withDO(c.DO.WithContext(ctx))
  316. }
  317. func (c certDo) ReadDB() *certDo {
  318. return c.Clauses(dbresolver.Read)
  319. }
  320. func (c certDo) WriteDB() *certDo {
  321. return c.Clauses(dbresolver.Write)
  322. }
  323. func (c certDo) Session(config *gorm.Session) *certDo {
  324. return c.withDO(c.DO.Session(config))
  325. }
  326. func (c certDo) Clauses(conds ...clause.Expression) *certDo {
  327. return c.withDO(c.DO.Clauses(conds...))
  328. }
  329. func (c certDo) Returning(value interface{}, columns ...string) *certDo {
  330. return c.withDO(c.DO.Returning(value, columns...))
  331. }
  332. func (c certDo) Not(conds ...gen.Condition) *certDo {
  333. return c.withDO(c.DO.Not(conds...))
  334. }
  335. func (c certDo) Or(conds ...gen.Condition) *certDo {
  336. return c.withDO(c.DO.Or(conds...))
  337. }
  338. func (c certDo) Select(conds ...field.Expr) *certDo {
  339. return c.withDO(c.DO.Select(conds...))
  340. }
  341. func (c certDo) Where(conds ...gen.Condition) *certDo {
  342. return c.withDO(c.DO.Where(conds...))
  343. }
  344. func (c certDo) Order(conds ...field.Expr) *certDo {
  345. return c.withDO(c.DO.Order(conds...))
  346. }
  347. func (c certDo) Distinct(cols ...field.Expr) *certDo {
  348. return c.withDO(c.DO.Distinct(cols...))
  349. }
  350. func (c certDo) Omit(cols ...field.Expr) *certDo {
  351. return c.withDO(c.DO.Omit(cols...))
  352. }
  353. func (c certDo) Join(table schema.Tabler, on ...field.Expr) *certDo {
  354. return c.withDO(c.DO.Join(table, on...))
  355. }
  356. func (c certDo) LeftJoin(table schema.Tabler, on ...field.Expr) *certDo {
  357. return c.withDO(c.DO.LeftJoin(table, on...))
  358. }
  359. func (c certDo) RightJoin(table schema.Tabler, on ...field.Expr) *certDo {
  360. return c.withDO(c.DO.RightJoin(table, on...))
  361. }
  362. func (c certDo) Group(cols ...field.Expr) *certDo {
  363. return c.withDO(c.DO.Group(cols...))
  364. }
  365. func (c certDo) Having(conds ...gen.Condition) *certDo {
  366. return c.withDO(c.DO.Having(conds...))
  367. }
  368. func (c certDo) Limit(limit int) *certDo {
  369. return c.withDO(c.DO.Limit(limit))
  370. }
  371. func (c certDo) Offset(offset int) *certDo {
  372. return c.withDO(c.DO.Offset(offset))
  373. }
  374. func (c certDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *certDo {
  375. return c.withDO(c.DO.Scopes(funcs...))
  376. }
  377. func (c certDo) Unscoped() *certDo {
  378. return c.withDO(c.DO.Unscoped())
  379. }
  380. func (c certDo) Create(values ...*model.Cert) error {
  381. if len(values) == 0 {
  382. return nil
  383. }
  384. return c.DO.Create(values)
  385. }
  386. func (c certDo) CreateInBatches(values []*model.Cert, batchSize int) error {
  387. return c.DO.CreateInBatches(values, batchSize)
  388. }
  389. // Save : !!! underlying implementation is different with GORM
  390. // The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
  391. func (c certDo) Save(values ...*model.Cert) error {
  392. if len(values) == 0 {
  393. return nil
  394. }
  395. return c.DO.Save(values)
  396. }
  397. func (c certDo) First() (*model.Cert, error) {
  398. if result, err := c.DO.First(); err != nil {
  399. return nil, err
  400. } else {
  401. return result.(*model.Cert), nil
  402. }
  403. }
  404. func (c certDo) Take() (*model.Cert, error) {
  405. if result, err := c.DO.Take(); err != nil {
  406. return nil, err
  407. } else {
  408. return result.(*model.Cert), nil
  409. }
  410. }
  411. func (c certDo) Last() (*model.Cert, error) {
  412. if result, err := c.DO.Last(); err != nil {
  413. return nil, err
  414. } else {
  415. return result.(*model.Cert), nil
  416. }
  417. }
  418. func (c certDo) Find() ([]*model.Cert, error) {
  419. result, err := c.DO.Find()
  420. return result.([]*model.Cert), err
  421. }
  422. func (c certDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.Cert, err error) {
  423. buf := make([]*model.Cert, 0, batchSize)
  424. err = c.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
  425. defer func() { results = append(results, buf...) }()
  426. return fc(tx, batch)
  427. })
  428. return results, err
  429. }
  430. func (c certDo) FindInBatches(result *[]*model.Cert, batchSize int, fc func(tx gen.Dao, batch int) error) error {
  431. return c.DO.FindInBatches(result, batchSize, fc)
  432. }
  433. func (c certDo) Attrs(attrs ...field.AssignExpr) *certDo {
  434. return c.withDO(c.DO.Attrs(attrs...))
  435. }
  436. func (c certDo) Assign(attrs ...field.AssignExpr) *certDo {
  437. return c.withDO(c.DO.Assign(attrs...))
  438. }
  439. func (c certDo) Joins(fields ...field.RelationField) *certDo {
  440. for _, _f := range fields {
  441. c = *c.withDO(c.DO.Joins(_f))
  442. }
  443. return &c
  444. }
  445. func (c certDo) Preload(fields ...field.RelationField) *certDo {
  446. for _, _f := range fields {
  447. c = *c.withDO(c.DO.Preload(_f))
  448. }
  449. return &c
  450. }
  451. func (c certDo) FirstOrInit() (*model.Cert, error) {
  452. if result, err := c.DO.FirstOrInit(); err != nil {
  453. return nil, err
  454. } else {
  455. return result.(*model.Cert), nil
  456. }
  457. }
  458. func (c certDo) FirstOrCreate() (*model.Cert, error) {
  459. if result, err := c.DO.FirstOrCreate(); err != nil {
  460. return nil, err
  461. } else {
  462. return result.(*model.Cert), nil
  463. }
  464. }
  465. func (c certDo) FindByPage(offset int, limit int) (result []*model.Cert, count int64, err error) {
  466. result, err = c.Offset(offset).Limit(limit).Find()
  467. if err != nil {
  468. return
  469. }
  470. if size := len(result); 0 < limit && 0 < size && size < limit {
  471. count = int64(size + offset)
  472. return
  473. }
  474. count, err = c.Offset(-1).Limit(-1).Count()
  475. return
  476. }
  477. func (c certDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
  478. count, err = c.Count()
  479. if err != nil {
  480. return
  481. }
  482. err = c.Offset(offset).Limit(limit).Scan(result)
  483. return
  484. }
  485. func (c certDo) Scan(result interface{}) (err error) {
  486. return c.DO.Scan(result)
  487. }
  488. func (c certDo) Delete(models ...*model.Cert) (result gen.ResultInfo, err error) {
  489. return c.DO.Delete(models)
  490. }
  491. func (c *certDo) withDO(do gen.Dao) *certDo {
  492. c.DO = *do.(*gen.DO)
  493. return c
  494. }