commit 2bddc363f20210ab019eec29d8ba4104d147e9b7
parent 4da080df88248875f8be0bb4ae44857d3fb0925c
Author: lash <dev@holbrook.no>
Date: Thu, 5 Sep 2024 16:44:18 +0100
Add debug string representation for dbs
Diffstat:
3 files changed, 20 insertions(+), 0 deletions(-)
diff --git a/db/fs/fs.go b/db/fs/fs.go
@@ -23,6 +23,7 @@ type fsDb struct {
dir string
}
+
// NewFsDb creates a filesystem backed Db implementation.
func NewFsDb() *fsDb {
db := &fsDb{
@@ -31,6 +32,11 @@ func NewFsDb() *fsDb {
return db
}
+// String implements the string interface.
+func(fdb *fsDb) String() string {
+ return "fsdb: " + fdb.dir
+}
+
// Connect implements the Db interface.
func(fdb *fsDb) Connect(ctx context.Context, connStr string) error {
if fdb.dir != "" {
diff --git a/db/gdbm/gdbm.go b/db/gdbm/gdbm.go
@@ -25,6 +25,15 @@ func NewGdbmDb() *gdbmDb {
return db
}
+// String implements the string interface.
+func(gdb *gdbmDb) String() string {
+ fn, err := gdb.conn.FileName()
+ if err != nil {
+ fn = "??"
+ }
+ return "gdbmdb: " + fn
+}
+
// Connect implements Db
func(gdb *gdbmDb) Connect(ctx context.Context, connStr string) error {
if gdb.conn != nil {
diff --git a/db/mem/mem.go b/db/mem/mem.go
@@ -28,6 +28,11 @@ func NewMemDb() *memDb {
return db
}
+// String implements the string interface.
+func(mdb *memDb) String() string {
+ return "memdb"
+}
+
// Connect implements Db
func(mdb *memDb) Connect(ctx context.Context, connStr string) error {
if mdb.store != nil {