Skip to content

Commit 33ec896

Browse files
committed
only build with lmdb on linux.
1 parent 2e4079f commit 33ec896

3 files changed

Lines changed: 55 additions & 29 deletions

File tree

lmdb.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//go:build linux && !riscv64
2+
3+
package main
4+
5+
import (
6+
"os"
7+
"path/filepath"
8+
9+
"fiatjaf.com/nostr/eventstore/lmdb"
10+
"fiatjaf.com/nostr/eventstore/nullstore"
11+
"fiatjaf.com/nostr/sdk"
12+
"fiatjaf.com/nostr/sdk/hints/lmdbh"
13+
lmdbkv "fiatjaf.com/nostr/sdk/kvstore/lmdb"
14+
"github.com/urfave/cli/v3"
15+
)
16+
17+
func setupLocalDatabases(c *cli.Command, sys *sdk.System) {
18+
configPath := c.String("config-path")
19+
if configPath != "" {
20+
hintsPath := filepath.Join(configPath, "outbox/hints")
21+
os.MkdirAll(hintsPath, 0755)
22+
_, err := lmdbh.NewLMDBHints(hintsPath)
23+
if err != nil {
24+
log("failed to create lmdb hints db at '%s': %s\n", hintsPath, err)
25+
}
26+
27+
eventsPath := filepath.Join(configPath, "events")
28+
os.MkdirAll(eventsPath, 0755)
29+
sys.Store = &lmdb.LMDBBackend{Path: eventsPath}
30+
if err := sys.Store.Init(); err != nil {
31+
log("failed to create boltdb events db at '%s': %s\n", eventsPath, err)
32+
sys.Store = &nullstore.NullStore{}
33+
}
34+
35+
kvPath := filepath.Join(configPath, "kvstore")
36+
os.MkdirAll(kvPath, 0755)
37+
if kv, err := lmdbkv.NewStore(kvPath); err != nil {
38+
log("failed to create boltdb kvstore db at '%s': %s\n", kvPath, err)
39+
} else {
40+
sys.KVStore = kv
41+
}
42+
}
43+
}

main.go

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@ import (
88
"path/filepath"
99

1010
"fiatjaf.com/nostr"
11-
"fiatjaf.com/nostr/eventstore/lmdb"
12-
"fiatjaf.com/nostr/eventstore/nullstore"
1311
"fiatjaf.com/nostr/sdk"
14-
"fiatjaf.com/nostr/sdk/hints/lmdbh"
15-
lmdbkv "fiatjaf.com/nostr/sdk/kvstore/lmdb"
1612
"github.com/fatih/color"
1713
"github.com/urfave/cli/v3"
1814
)
@@ -103,31 +99,7 @@ var app = &cli.Command{
10399
Before: func(ctx context.Context, c *cli.Command) (context.Context, error) {
104100
sys = sdk.NewSystem()
105101

106-
configPath := c.String("config-path")
107-
if configPath != "" {
108-
hintsPath := filepath.Join(configPath, "outbox/hints")
109-
os.MkdirAll(hintsPath, 0755)
110-
_, err := lmdbh.NewLMDBHints(hintsPath)
111-
if err != nil {
112-
log("failed to create lmdb hints db at '%s': %s\n", hintsPath, err)
113-
}
114-
115-
eventsPath := filepath.Join(configPath, "events")
116-
os.MkdirAll(eventsPath, 0755)
117-
sys.Store = &lmdb.LMDBBackend{Path: eventsPath}
118-
if err := sys.Store.Init(); err != nil {
119-
log("failed to create boltdb events db at '%s': %s\n", eventsPath, err)
120-
sys.Store = &nullstore.NullStore{}
121-
}
122-
123-
kvPath := filepath.Join(configPath, "kvstore")
124-
os.MkdirAll(kvPath, 0755)
125-
if kv, err := lmdbkv.NewStore(kvPath); err != nil {
126-
log("failed to create boltdb kvstore db at '%s': %s\n", kvPath, err)
127-
} else {
128-
sys.KVStore = kv
129-
}
130-
}
102+
setupLocalDatabases(c, sys)
131103

132104
sys.Pool = nostr.NewPool(nostr.PoolOptions{
133105
AuthorKindQueryMiddleware: sys.TrackQueryAttempts,

non_lmdb.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//go:build !linux || riscv64
2+
3+
package main
4+
5+
import (
6+
"fiatjaf.com/nostr/sdk"
7+
"github.com/urfave/cli/v3"
8+
)
9+
10+
func setupLocalDatabases(c *cli.Command, sys *sdk.System) {
11+
}

0 commit comments

Comments
 (0)