eventstore: add boltdb support to cli.

This commit is contained in:
fiatjaf
2025-08-05 23:40:23 -03:00
parent 414e836eaa
commit 4a7e893b80
2 changed files with 7 additions and 11 deletions

View File

@@ -28,7 +28,8 @@ func detect(dir string) (string, error) {
return "", err return "", err
} }
if !f.IsDir() { if !f.IsDir() {
return "", fmt.Errorf("unknown db format") // only boltdb is a file for now
return "boltdb", nil
} }
entries, err := os.ReadDir(dir) entries, err := os.ReadDir(dir)
@@ -49,14 +50,6 @@ func detect(dir string) (string, error) {
} }
} }
} }
// for _, entry := range entries {
// if strings.HasSuffix(entry.Name(), ".mdb") {
// return "lmdb", nil
// }
// if strings.HasSuffix(entry.Name(), ".vlog") {
// return "badger", nil
// }
// }
return "", fmt.Errorf("undetected") return "", fmt.Errorf("undetected")
} }

View File

@@ -11,6 +11,7 @@ import (
"fiatjaf.com/nostr" "fiatjaf.com/nostr"
"fiatjaf.com/nostr/eventstore" "fiatjaf.com/nostr/eventstore"
"fiatjaf.com/nostr/eventstore/boltdb"
"fiatjaf.com/nostr/eventstore/lmdb" "fiatjaf.com/nostr/eventstore/lmdb"
"fiatjaf.com/nostr/eventstore/slicestore" "fiatjaf.com/nostr/eventstore/slicestore"
"github.com/urfave/cli/v3" "github.com/urfave/cli/v3"
@@ -32,11 +33,11 @@ var app = &cli.Command{
&cli.StringFlag{ &cli.StringFlag{
Name: "type", Name: "type",
Aliases: []string{"t"}, Aliases: []string{"t"},
Usage: "store type ('lmdb', 'mmm')", Usage: "store type ('lmdb', 'boltdb', 'mmm')",
}, },
}, },
Before: func(ctx context.Context, c *cli.Command) (context.Context, error) { Before: func(ctx context.Context, c *cli.Command) (context.Context, error) {
path := strings.Trim(c.String("store"), "/") path := strings.TrimSuffix(c.String("store"), "/")
typ := c.String("type") typ := c.String("type")
if typ != "" { if typ != "" {
// bypass automatic detection // bypass automatic detection
@@ -70,6 +71,8 @@ var app = &cli.Command{
switch typ { switch typ {
case "lmdb": case "lmdb":
db = &lmdb.LMDBBackend{Path: path} db = &lmdb.LMDBBackend{Path: path}
case "boltdb":
db = &boltdb.BoltBackend{Path: path}
case "mmm": case "mmm":
var err error var err error
if db, err = doMmmInit(path); err != nil { if db, err = doMmmInit(path); err != nil {