2024-11-03 00:33:52 +01:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
2024-11-04 03:23:30 +01:00
|
|
|
"context"
|
|
|
|
"errors"
|
2024-11-03 00:41:08 +01:00
|
|
|
|
2024-11-04 03:23:30 +01:00
|
|
|
"git.defalsify.org/vise.git/db"
|
|
|
|
"git.defalsify.org/vise.git/resource"
|
|
|
|
"git.defalsify.org/vise.git/persist"
|
2024-11-03 00:41:08 +01:00
|
|
|
"git.grassecon.net/urdt/ussd/internal/storage"
|
2024-11-03 00:33:52 +01:00
|
|
|
)
|
|
|
|
|
2024-11-03 00:41:08 +01:00
|
|
|
func StoreToDb(store *UserDataStore) db.Db {
|
|
|
|
return store.Db
|
|
|
|
}
|
|
|
|
|
|
|
|
func StoreToPrefixDb(store *UserDataStore, pfx []byte) storage.PrefixDb {
|
|
|
|
return storage.NewSubPrefixDb(store.Db, pfx)
|
2024-11-03 00:33:52 +01:00
|
|
|
}
|
2024-11-04 03:23:30 +01:00
|
|
|
|
|
|
|
type StorageServices interface {
|
|
|
|
GetPersister(ctx context.Context) (*persist.Persister, error)
|
|
|
|
GetUserdataDb(ctx context.Context) (db.Db, error)
|
|
|
|
GetResource(ctx context.Context) (resource.Resource, error)
|
|
|
|
EnsureDbDir() error
|
|
|
|
}
|
|
|
|
|
|
|
|
type StorageService struct {
|
|
|
|
svc *storage.MenuStorageService
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewStorageService(dbDir string) *StorageService {
|
|
|
|
return &StorageService{
|
|
|
|
svc: storage.NewMenuStorageService(dbDir, ""),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func(ss *StorageService) GetPersister(ctx context.Context) (*persist.Persister, error) {
|
|
|
|
return ss.svc.GetPersister(ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
func(ss *StorageService) GetUserdataDb(ctx context.Context) (db.Db, error) {
|
|
|
|
return ss.svc.GetUserdataDb(ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
func(ss *StorageService) GetResource(ctx context.Context) (resource.Resource, error) {
|
|
|
|
return nil, errors.New("not implemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
func(ss *StorageService) EnsureDbDir() error {
|
|
|
|
return ss.svc.EnsureDbDir()
|
|
|
|
}
|