From 51632dcc9fce79d0ada34947485d5424c650c770 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Mon, 17 Mar 2025 13:34:35 -0300 Subject: [PATCH] update blossom example to use a different database. closes https://github.com/fiatjaf/khatru/issues/36 --- docs/core/blossom.md | 3 ++- examples/blossom/main.go | 9 ++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/docs/core/blossom.md b/docs/core/blossom.md index e2703d3..2d24758 100644 --- a/docs/core/blossom.md +++ b/docs/core/blossom.md @@ -18,7 +18,8 @@ func main() { bl := blossom.New(relay, "http://localhost:3334") // create a database for keeping track of blob metadata - bl.Store = blossom.EventStoreBlobIndexWrapper{Store: db, ServiceURL: bl.ServiceURL} + // (do not use the same database used for the relay events) + bl.Store = blossom.EventStoreBlobIndexWrapper{Store: blobdb, ServiceURL: bl.ServiceURL} // implement the required storage functions bl.StoreBlob = append(bl.StoreBlob, func(ctx context.Context, sha256 string, body []byte) error { diff --git a/examples/blossom/main.go b/examples/blossom/main.go index c96f5e5..c5cf4ef 100644 --- a/examples/blossom/main.go +++ b/examples/blossom/main.go @@ -15,19 +15,22 @@ import ( func main() { relay := khatru.NewRelay() - db := &badger.BadgerBackend{Path: "/tmp/khatru-badger-blossom-tmp"} + db := &badger.BadgerBackend{Path: "/tmp/khatru-badger-tmp"} if err := db.Init(); err != nil { panic(err) } - relay.StoreEvent = append(relay.StoreEvent, db.SaveEvent) relay.QueryEvents = append(relay.QueryEvents, db.QueryEvents) relay.CountEvents = append(relay.CountEvents, db.CountEvents) relay.DeleteEvent = append(relay.DeleteEvent, db.DeleteEvent) relay.ReplaceEvent = append(relay.ReplaceEvent, db.ReplaceEvent) + bdb := &badger.BadgerBackend{Path: "/tmp/khatru-badger-blossom-tmp"} + if err := bdb.Init(); err != nil { + panic(err) + } bl := blossom.New(relay, "http://localhost:3334") - bl.Store = blossom.EventStoreBlobIndexWrapper{Store: db, ServiceURL: bl.ServiceURL} + bl.Store = blossom.EventStoreBlobIndexWrapper{Store: bdb, ServiceURL: bl.ServiceURL} bl.StoreBlob = append(bl.StoreBlob, func(ctx context.Context, sha256 string, body []byte) error { fmt.Println("storing", sha256, len(body)) return nil