rename struct storage
This commit is contained in:
parent
790a4db3ca
commit
1eeb6607be
@ -129,7 +129,7 @@ func NewService(ctx context.Context) (micro.Service, error) {
|
|||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
|
|
||||||
mux.HandleFunc("/listPackage", handler.Methods(http.MethodGet, h.ListPackage))
|
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("/addComment", handler.Methods(http.MethodPut, h.AddComment))
|
||||||
mux.HandleFunc("/addPackage", handler.Methods(http.MethodPost, h.AddPackage))
|
mux.HandleFunc("/addPackage", handler.Methods(http.MethodPost, h.AddPackage))
|
||||||
|
|
||||||
|
@ -24,22 +24,22 @@ const (
|
|||||||
pathMigration = `migrations/sqlite`
|
pathMigration = `migrations/sqlite`
|
||||||
)
|
)
|
||||||
|
|
||||||
type Postgres struct {
|
type Sqlite struct {
|
||||||
db *sql.DB
|
db *sql.DB
|
||||||
fs embed.FS
|
fs embed.FS
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewStorage(db *sql.DB) (interface{}, error) {
|
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) {
|
func NewStorageFS(fs embed.FS) func(*sql.DB) (interface{}, error) {
|
||||||
return func(db *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{
|
driver, err := sqlite.WithInstance(s.db, &sqlite.Config{
|
||||||
MigrationsTable: sqlite.DefaultMigrationsTable,
|
MigrationsTable: sqlite.DefaultMigrationsTable,
|
||||||
DatabaseName: config.ServiceName,
|
DatabaseName: config.ServiceName,
|
||||||
@ -65,7 +65,7 @@ func (s *Postgres) MigrateUp() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Postgres) MigrateDown() error {
|
func (s *Sqlite) MigrateDown() error {
|
||||||
driver, err := sqlite.WithInstance(s.db, &sqlite.Config{
|
driver, err := sqlite.WithInstance(s.db, &sqlite.Config{
|
||||||
MigrationsTable: sqlite.DefaultMigrationsTable,
|
MigrationsTable: sqlite.DefaultMigrationsTable,
|
||||||
DatabaseName: config.ServiceName,
|
DatabaseName: config.ServiceName,
|
||||||
@ -91,11 +91,11 @@ func (s *Postgres) MigrateDown() error {
|
|||||||
return nil
|
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")
|
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)
|
rows, err := s.db.QueryContext(ctx, queryListPackage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -124,7 +124,7 @@ func (s *Postgres) ListPackage(ctx context.Context) (models.ListPackage, error)
|
|||||||
return result, err
|
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)
|
tx, err := s.db.BeginTx(ctx, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -154,7 +154,7 @@ func (s *Postgres) AddComment(ctx context.Context, rsp *pb.AddCommentRsp) error
|
|||||||
return err
|
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)
|
tx, err := s.db.BeginTx(ctx, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -184,7 +184,7 @@ func (s *Postgres) AddPackage(ctx context.Context, rsp *pb.AddPackageRsp) error
|
|||||||
return err
|
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)
|
tx, err := s.db.BeginTx(ctx, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
Loading…
Reference in New Issue
Block a user