postgres-switch #113

Merged
lash merged 14 commits from postgres-switch into master 2024-10-22 16:04:56 +02:00
2 changed files with 2 additions and 75 deletions
Showing only changes of commit 9f562fe53e - Show all commits

View File

@ -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
}

View File

@ -8,6 +8,7 @@ import (
"git.defalsify.org/vise.git/db" "git.defalsify.org/vise.git/db"
fsdb "git.defalsify.org/vise.git/db/fs" 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/logging"
"git.defalsify.org/vise.git/persist" "git.defalsify.org/vise.git/persist"
"git.defalsify.org/vise.git/resource" "git.defalsify.org/vise.git/resource"
@ -67,7 +68,7 @@ func (ms *MenuStorageService) getOrCreateDb(ctx context.Context, existingDb db.D
var err error var err error
if database == "postgres" { if database == "postgres" {
newDb = NewPostgresDb() newDb = postgres.NewPgDb()
connStr := buildConnStr() connStr := buildConnStr()
err = newDb.Connect(ctx, connStr) err = newDb.Connect(ctx, connStr)
} else { } else {
Alfred-mk marked this conversation as resolved Outdated
Outdated
Review

postgres shouold be implemented for both userdatatstore and state store

postgres shouold be implemented for both userdatatstore and state store