diff --git a/internal/storage/postgres.go b/internal/storage/postgres.go deleted file mode 100644 index 9422a26..0000000 --- a/internal/storage/postgres.go +++ /dev/null @@ -1,74 +0,0 @@ -package storage - -import ( - "context" - - "git.defalsify.org/vise.git/db" - postgres "git.defalsify.org/vise.git/db/postgres" - "git.defalsify.org/vise.git/lang" -) - -type PostgresDb struct { - db db.Db - connStr string -} - -func NewPostgresDb() *PostgresDb { - return &PostgresDb{} -} - -func (pdb *PostgresDb) Connect(ctx context.Context, connStr string) error { - if pdb.db != nil { - logg.WarnCtxf(ctx, "already connected, skipping", "connStr", connStr) - return nil - } - postgresdb := postgres.NewPgDb().WithSchema("public") - err := postgresdb.Connect(ctx, connStr) - if err != nil { - return err - } - pdb.db = postgresdb - pdb.connStr = connStr - return nil -} - -func (pdb *PostgresDb) SetPrefix(pfx uint8) { - pdb.db.SetPrefix(pfx) -} - -func (pdb *PostgresDb) SetSession(sessionId string) { - pdb.db.SetSession(sessionId) -} - -func (pdb *PostgresDb) SetLanguage(lng *lang.Language) { - pdb.db.SetLanguage(lng) -} - -func (pdb *PostgresDb) Safe() bool { - return pdb.db.Safe() -} - -func (pdb *PostgresDb) Prefix() uint8 { - return pdb.db.Prefix() -} - -func (pdb *PostgresDb) SetLock(typ uint8, locked bool) error { - return pdb.db.SetLock(typ, locked) -} - -func (pdb *PostgresDb) Put(ctx context.Context, key []byte, val []byte) error { - return pdb.db.Put(ctx, key, val) -} - -func (pdb *PostgresDb) Get(ctx context.Context, key []byte) ([]byte, error) { - return pdb.db.Get(ctx, key) -} - -func (pdb *PostgresDb) Close() error { - if pdb.db == nil { - return nil - } - err := pdb.db.Close() - pdb.db = nil - return err -} \ No newline at end of file diff --git a/internal/storage/storageservice.go b/internal/storage/storageservice.go index c616019..9fa1839 100644 --- a/internal/storage/storageservice.go +++ b/internal/storage/storageservice.go @@ -8,6 +8,7 @@ import ( "git.defalsify.org/vise.git/db" fsdb "git.defalsify.org/vise.git/db/fs" + "git.defalsify.org/vise.git/db/postgres" "git.defalsify.org/vise.git/logging" "git.defalsify.org/vise.git/persist" "git.defalsify.org/vise.git/resource" @@ -67,7 +68,7 @@ func (ms *MenuStorageService) getOrCreateDb(ctx context.Context, existingDb db.D var err error if database == "postgres" { - newDb = NewPostgresDb() + newDb = postgres.NewPgDb() connStr := buildConnStr() err = newDb.Connect(ctx, connStr) } else {