pkgdash/storage/storage.go

39 lines
1.1 KiB
Go
Raw Normal View History

package storage
import (
"context"
"database/sql"
"embed"
cmsstorage "go.unistack.org/cms-service/storage"
"go.unistack.org/unistack-org/pkgdash/models"
pb "go.unistack.org/unistack-org/pkgdash/proto"
"go.unistack.org/unistack-org/pkgdash/storage/postgres"
"go.unistack.org/unistack-org/pkgdash/storage/sqlite"
)
//go:embed migrations
var fs embed.FS
var storages = cmsstorage.NewStorageInterface()
func init() {
storages.RegisterStorage("postgres", postgres.NewStorageFS(fs))
storages.RegisterStorage("sqlite", sqlite.NewStorageFS(fs))
}
type Storage interface {
cmsstorage.Migrator
ListPackage(ctx context.Context) (models.ListPackage, error)
UpdatePackage(ctx context.Context, req *pb.UpdatePackageReq) error
AddComment(ctx context.Context, req *pb.AddCommentReq) error
AddPackage(ctx context.Context, req *pb.AddPackageReq) error
InsertButchModules(ctx context.Context, req []models.Module) ([]uint64, error)
GetModule(ctx context.Context, req *pb.GetModuleReq) (models.ListModule, error)
}
func NewStorage(name string, db *sql.DB) (interface{}, error) {
return storages.NewStorage(name, db)
}