model.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package model
  2. import (
  3. "time"
  4. "gorm.io/gen"
  5. "gorm.io/gorm"
  6. )
  7. var db *gorm.DB
  8. type Model struct {
  9. ID uint64 `gorm:"primary_key" json:"id"`
  10. CreatedAt time.Time `json:"created_at"`
  11. UpdatedAt time.Time `json:"updated_at"`
  12. DeletedAt *gorm.DeletedAt `gorm:"index" json:"deleted_at,omitempty"`
  13. }
  14. func GenerateAllModel() []any {
  15. return []any{
  16. ConfigBackup{},
  17. User{},
  18. AuthToken{},
  19. Cert{},
  20. ChatGPTLog{},
  21. Site{},
  22. Stream{},
  23. DnsCredential{},
  24. Environment{},
  25. Notification{},
  26. AcmeUser{},
  27. BanIP{},
  28. Config{},
  29. Passkey{},
  30. EnvGroup{},
  31. ExternalNotify{},
  32. AutoBackup{},
  33. }
  34. }
  35. func Use(tx *gorm.DB) {
  36. db = tx
  37. }
  38. func UseDB() *gorm.DB {
  39. return db
  40. }
  41. type Pagination struct {
  42. Total int64 `json:"total"`
  43. PerPage int `json:"per_page"`
  44. CurrentPage int `json:"current_page"`
  45. TotalPages int64 `json:"total_pages"`
  46. }
  47. type DataList struct {
  48. Data interface{} `json:"data"`
  49. Pagination Pagination `json:"pagination,omitempty"`
  50. }
  51. type Method interface {
  52. // FirstByID Where("id=@id")
  53. FirstByID(id uint64) (*gen.T, error)
  54. // DeleteByID update @@table set deleted_at=strftime('%Y-%m-%d %H:%M:%S','now') where id=@id
  55. DeleteByID(id uint64) error
  56. }