store.go 981 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package store
  2. import (
  3. "context"
  4. "sync"
  5. "github.com/usememos/memos/server/profile"
  6. )
  7. // Store provides database access to all raw objects.
  8. type Store struct {
  9. Profile *profile.Profile
  10. driver Driver
  11. systemSettingCache sync.Map // map[string]*SystemSetting
  12. userCache sync.Map // map[int]*User
  13. userSettingCache sync.Map // map[string]*UserSetting
  14. idpCache sync.Map // map[int]*IdentityProvider
  15. }
  16. // New creates a new instance of Store.
  17. func New(driver Driver, profile *profile.Profile) *Store {
  18. return &Store{
  19. Profile: profile,
  20. driver: driver,
  21. }
  22. }
  23. func (s *Store) BackupTo(ctx context.Context, filename string) error {
  24. return s.driver.BackupTo(ctx, filename)
  25. }
  26. func (s *Store) Vacuum(ctx context.Context) error {
  27. return s.driver.Vacuum(ctx)
  28. }
  29. func (s *Store) Close() error {
  30. return s.driver.Close()
  31. }
  32. func (s *Store) GetCurrentDBSize(ctx context.Context) (int64, error) {
  33. return s.driver.GetCurrentDBSize(ctx)
  34. }