rename struct storage

This commit is contained in:
Денис Евстигнеев 2023-08-10 22:35:48 +03:00
parent 790a4db3ca
commit 1eeb6607be
2 changed files with 11 additions and 11 deletions

View File

@ -129,7 +129,7 @@ func NewService(ctx context.Context) (micro.Service, error) {
mux := http.NewServeMux()
mux.HandleFunc("/listPackage", handler.Methods(http.MethodGet, h.ListPackage))
mux.HandleFunc("/updateInfo", handler.Methods(http.MethodPost, h.UpdatePackage))
mux.HandleFunc("/updatePackage", handler.Methods(http.MethodPost, h.UpdatePackage))
mux.HandleFunc("/addComment", handler.Methods(http.MethodPut, h.AddComment))
mux.HandleFunc("/addPackage", handler.Methods(http.MethodPost, h.AddPackage))

View File

@ -24,22 +24,22 @@ const (
pathMigration = `migrations/sqlite`
)
type Postgres struct {
type Sqlite struct {
db *sql.DB
fs embed.FS
}
func NewStorage(db *sql.DB) (interface{}, error) {
return &Postgres{db: db}, nil
return &Sqlite{db: db}, nil
}
func NewStorageFS(fs embed.FS) func(*sql.DB) (interface{}, error) {
return func(db *sql.DB) (interface{}, error) {
return &Postgres{db: db, fs: fs}, nil
return &Sqlite{db: db, fs: fs}, nil
}
}
func (s *Postgres) MigrateUp() error {
func (s *Sqlite) MigrateUp() error {
driver, err := sqlite.WithInstance(s.db, &sqlite.Config{
MigrationsTable: sqlite.DefaultMigrationsTable,
DatabaseName: config.ServiceName,
@ -65,7 +65,7 @@ func (s *Postgres) MigrateUp() error {
return nil
}
func (s *Postgres) MigrateDown() error {
func (s *Sqlite) MigrateDown() error {
driver, err := sqlite.WithInstance(s.db, &sqlite.Config{
MigrationsTable: sqlite.DefaultMigrationsTable,
DatabaseName: config.ServiceName,
@ -91,11 +91,11 @@ func (s *Postgres) MigrateDown() error {
return nil
}
func (s *Postgres) UpdatePackage(ctx context.Context, rsp *pb.UpdatePackageRsp) error {
func (s *Sqlite) UpdatePackage(ctx context.Context, rsp *pb.UpdatePackageRsp) error {
panic("need implement")
}
func (s *Postgres) ListPackage(ctx context.Context) (models.ListPackage, error) {
func (s *Sqlite) ListPackage(ctx context.Context) (models.ListPackage, error) {
rows, err := s.db.QueryContext(ctx, queryListPackage)
if err != nil {
return nil, err
@ -124,7 +124,7 @@ func (s *Postgres) ListPackage(ctx context.Context) (models.ListPackage, error)
return result, err
}
func (s *Postgres) AddComment(ctx context.Context, rsp *pb.AddCommentRsp) error {
func (s *Sqlite) AddComment(ctx context.Context, rsp *pb.AddCommentRsp) error {
tx, err := s.db.BeginTx(ctx, nil)
if err != nil {
return err
@ -154,7 +154,7 @@ func (s *Postgres) AddComment(ctx context.Context, rsp *pb.AddCommentRsp) error
return err
}
func (s *Postgres) AddPackage(ctx context.Context, rsp *pb.AddPackageRsp) error {
func (s *Sqlite) AddPackage(ctx context.Context, rsp *pb.AddPackageRsp) error {
tx, err := s.db.BeginTx(ctx, nil)
if err != nil {
return err
@ -184,7 +184,7 @@ func (s *Postgres) AddPackage(ctx context.Context, rsp *pb.AddPackageRsp) error
return err
}
func (s *Postgres) InsertButchModules(ctx context.Context, rsp []models.Module) ([]uint64, error) {
func (s *Sqlite) InsertButchModules(ctx context.Context, rsp []models.Module) ([]uint64, error) {
tx, err := s.db.BeginTx(ctx, nil)
if err != nil {
return nil, err