Add debug string for db type in menuhandler

This commit is contained in:
lash 2025-01-12 15:35:44 +00:00
parent 9e4c65c8b4
commit 3f8e08151a
Signed by untrusted user who does not match committer: lash
GPG Key ID: 21D2E7BB88C2A746

View File

@ -27,6 +27,7 @@ type StorageService interface {
GetResource(ctx context.Context) (resource.Resource, error)
}
// TODO: Support individual backend for each store (conndata)
type MenuStorageService struct {
conn ConnData
resourceDir string
@ -48,7 +49,8 @@ func (ms *MenuStorageService) WithResourceDir(resourceDir string) *MenuStorageSe
return ms
}
func (ms *MenuStorageService) getOrCreateDb(ctx context.Context, existingDb db.Db, section string) (db.Db, error) {
// TODO: allow fsdb, memdb
func (ms *MenuStorageService) getOrCreateDb(ctx context.Context, existingDb db.Db, section string, typ string) (db.Db, error) {
var newDb db.Db
var err error
@ -56,7 +58,6 @@ func (ms *MenuStorageService) getOrCreateDb(ctx context.Context, existingDb db.D
return existingDb, nil
}
connStr := ms.conn.String()
dbTyp := ms.conn.DbType()
if dbTyp == DBTYPE_POSTGRES {
@ -76,7 +77,7 @@ func (ms *MenuStorageService) getOrCreateDb(ctx context.Context, existingDb db.D
} else {
return nil, fmt.Errorf("unsupported connection string: '%s'\n", ms.conn.String())
}
logg.DebugCtxf(ctx, "connecting to db", "conn", connStr, "conndata", ms.conn)
logg.DebugCtxf(ctx, "connecting to db", "conn", connStr, "conndata", ms.conn, "typ", typ)
err = newDb.Connect(ctx, connStr)
if err != nil {
return nil, err
@ -140,7 +141,7 @@ func (ms *MenuStorageService) GetUserdataDb(ctx context.Context) (db.Db, error)
return ms.userDataStore, nil
}
userDataStore, err := ms.getOrCreateDb(ctx, ms.userDataStore, "userdata.gdbm")
userDataStore, err := ms.getOrCreateDb(ctx, ms.userDataStore, "userdata.gdbm", "userdata")
if err != nil {
return nil, err
}
@ -169,7 +170,7 @@ func (ms *MenuStorageService) GetStateStore(ctx context.Context) (db.Db, error)
return ms.stateStore, nil
}
stateStore, err := ms.getOrCreateDb(ctx, ms.stateStore, "state.gdbm")
stateStore, err := ms.getOrCreateDb(ctx, ms.stateStore, "state.gdbm", "state")
if err != nil {
return nil, err
}