Skip to content

Commit

Permalink
Init nostr-sdk-rosckdb crate
Browse files Browse the repository at this point in the history
  • Loading branch information
yukibtc committed Oct 27, 2023
1 parent 8602437 commit 54795e0
Show file tree
Hide file tree
Showing 5 changed files with 572 additions and 2 deletions.
183 changes: 181 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions crates/nostr-sdk-rocksdb/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[package]
name = "nostr-sdk-rocksdb"
version = "0.1.0"
edition = "2021"
description = "TODO"
authors = ["Yuki Kishimoto <[email protected]>"]
homepage.workspace = true
repository.workspace = true
license.workspace = true
readme = "README.md"
rust-version.workspace = true
keywords = ["nostr", "sdk", "db", "redb"]

[dependencies]
nostr = { workspace = true, features = ["std"] }
nostr-sdk-db = { version = "0.1", path = "../nostr-sdk-db" }
nostr-sdk-fbs = { version = "0.1", path = "../nostr-sdk-fbs" }
rocksdb = { version = "0.21", default-features = false, features = ["multi-threaded-cf", "snappy"] }
tokio = { workspace = true, features = ["rt-multi-thread", "sync"] }
tracing = { workspace = true, features = ["std"] }

[dev-dependencies]
tokio = { workspace = true, features = ["macros", "rt-multi-thread", "time"] }
tracing-subscriber = { workspace = true, features = ["env-filter"] }
64 changes: 64 additions & 0 deletions crates/nostr-sdk-rocksdb/examples/rocksdb.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright (c) 2022-2023 Yuki Kishimoto
// Distributed under the MIT software license

use std::time::{Duration, Instant};

use nostr::prelude::*;
use nostr_sdk_db::NostrDatabase;
use nostr_sdk_rocksdb::RocksDatabase;
use tracing_subscriber::fmt::format::FmtSpan;

#[tokio::main]
async fn main() {
tracing_subscriber::fmt::fmt()
.with_span_events(FmtSpan::CLOSE)
.init();

let secret_key =
SecretKey::from_bech32("nsec1j4c6269y9w0q2er2xjw8sv2ehyrtfxq3jwgdlxj6qfn8z4gjsq5qfvfk99")
.unwrap();
let keys = Keys::new(secret_key);
let database = RocksDatabase::new("./db/rocksdb").unwrap();

/* for i in 0..50_000 {
let event = EventBuilder::new_text_note(format!("Event #{i}"), &[])
.to_event(&keys)
.unwrap();
database.save_event(&event).await.unwrap();
let event = EventBuilder::new_text_note(
format!("Reply to event #{i}"),
&[
Tag::Event(event.id, None, None),
Tag::PubKey(event.pubkey, None),
],
)
.to_event(&keys)
.unwrap();
database.save_event(&event).await.unwrap();
println!("{}", event.id);
}
for i in 0..10 {
let metadata = Metadata::new().name(format!("Name #{i}"));
let event = EventBuilder::set_metadata(metadata)
.to_event(&keys)
.unwrap();
database.save_event(&event).await.unwrap();
tokio::time::sleep(Duration::from_secs(1)).await;
} */

/* let event_id =
EventId::from_hex("b02c1c57a7c5b0e10245df8c26b429ad1a2cbf91d7cada3ecdb524b7e1d984b6")
.unwrap();
let event = database.event_by_id(event_id).await.unwrap();
println!("{event:?}"); */

let events = database
.query(vec![Filter::new()
.kind(Kind::Metadata)
.author(keys.public_key().to_string())])
.await
.unwrap();
println!("Got {} events", events.len());
}
Loading

0 comments on commit 54795e0

Please sign in to comment.