pkgdash/storage/storage.go
2023-08-10 22:16:14 +03:00

40 lines
1.0 KiB
Go

package storage
import (
"context"
"database/sql"
"embed"
"go.unistack.org/unistack-org/pkgdash/models"
pb "go.unistack.org/unistack-org/pkgdash/proto/go_generate"
"go.unistack.org/unistack-org/pkgdash/storage/postgres"
"go.unistack.org/unistack-org/pkgdash/storage/sqlite"
cmsstorage "go.unistack.org/cms-service/storage"
)
//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, rsp *pb.UpdatePackageRsp) error
AddComment(ctx context.Context, rsp *pb.AddCommentRsp) error
AddPackage(ctx context.Context, rsp *pb.AddPackageRsp) error
InsertButchModules(ctx context.Context, rsp []models.Module) ([]uint64, error)
}
func NewStorage(name string, db *sql.DB) (interface{}, error) {
return storages.NewStorage(name, db)
}