Skip to content

Commit

Permalink
ndb: bump nostr-ndb to 0.4
Browse files Browse the repository at this point in the history
Fixes #454

Signed-off-by: Yuki Kishimoto <[email protected]>
  • Loading branch information
yukibtc committed Nov 29, 2024
1 parent 7f8cd41 commit 8406f41
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 19 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@

### Changed

* Bump `async-utility` to 0.3 and `async-wsocket` to 0.11 ([Yuki Kishimoto])
* Bump `async-utility` to 0.3, `async-wsocket` to 0.11 and `atomic-destructor` to 0.3 ([Yuki Kishimoto])
* nostr: remove self-tagging when building events ([Yuki Kishimoto])
* lmdb: use `async-utility` to spawn blocking tasks ([Yuki Kishimoto])
* ndb: bump `nostr-ndb` to 0.4 ([Yuki Kishimoto])
* pool: add `PingTracker` and improve relay ping management ([Yuki Kishimoto])

### Added
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

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

4 changes: 0 additions & 4 deletions bindings/nostr-sdk-ffi/python/examples/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ async def main():
# Create/open LMDB database
database = NostrDatabase.lmdb("nostr-lmdb")

# NOT AVAILABLE ON WINDOWS AT THE MOMENT!
# Create/open nostrdb database
# database = NostrDatabase.ndb("ndb")

client = ClientBuilder().database(database).build()

await client.add_relay("wss://relay.damus.io")
Expand Down
2 changes: 1 addition & 1 deletion crates/nostr-ndb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ keywords = ["nostr", "database", "ndb", "nostrdb"]
async-trait.workspace = true
nostr = { workspace = true, features = ["std"] }
nostr-database.workspace = true
nostrdb = "0.3"
nostrdb = "0.4"
tracing = { workspace = true, features = ["std", "attributes"] }
21 changes: 10 additions & 11 deletions crates/nostr-ndb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ impl NdbDatabase {
txn: &'a Transaction,
filters: Vec<Filter>,
) -> Result<Vec<QueryResult<'a>>, DatabaseError> {
let filters = filters.into_iter().map(ndb_filter_conversion).collect();
let filters: Vec<nostrdb::Filter> =
filters.into_iter().map(ndb_filter_conversion).collect();
self.db
.query(txn, filters, MAX_RESULTS)
.query(txn, &filters, MAX_RESULTS)
.map_err(DatabaseError::backend)
}
}
Expand Down Expand Up @@ -184,41 +185,39 @@ fn ndb_filter_conversion(f: Filter) -> nostrdb::Filter {

if let Some(ids) = f.ids {
if !ids.is_empty() {
let ids: Vec<[u8; 32]> = ids.into_iter().map(|p| p.to_bytes()).collect();
filter.ids(ids);
filter = filter.ids(ids.iter().map(|p| p.as_bytes()));
}
}

if let Some(authors) = f.authors {
if !authors.is_empty() {
let authors: Vec<[u8; 32]> = authors.into_iter().map(|p| p.serialize()).collect();
filter.authors(authors);
filter = filter.authors(authors.iter());
}
}

if let Some(kinds) = f.kinds {
if !kinds.is_empty() {
let kinds: Vec<u64> = kinds.into_iter().map(|p| p.as_u16() as u64).collect();
filter.kinds(kinds);
filter = filter.kinds(kinds.into_iter().map(|p| p.as_u16() as u64));
}
}

if !f.generic_tags.is_empty() {
for (single_letter, set) in f.generic_tags.into_iter() {
filter.tags(set.into_iter().collect(), single_letter.as_char());
filter = filter.tags(set, single_letter.as_char());
}
}

if let Some(since) = f.since {
filter.since(since.as_u64());
filter = filter.since(since.as_u64());
}

if let Some(until) = f.until {
filter.until(until.as_u64());
filter = filter.until(until.as_u64());
}

if let Some(limit) = f.limit {
filter.limit(limit as u64);
filter = filter.limit(limit as u64);
}

filter.build()
Expand Down

0 comments on commit 8406f41

Please sign in to comment.