-
-
Notifications
You must be signed in to change notification settings - Fork 132
Nostr sqldb #835
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nostr sqldb #835
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! I just had a quick look.
Since diesel
support both PostgreSQL, SQLite and MySQL, maybe is better to rename this crate to something like nostr-sql
(or maybe a better name) and add also the support for SQLite (in another PR). What do you think? Is the schema defined for PostgreSQL compatible also with SQLite, right?
I see that the SQLite implementation in diesel
should work also in WASM, so this will allow to finally drop the nostr-indexeddb
crate.
Yes sounds good, I will rename the module to There will probably be some breaking changes when I add multi db support later (probably need some feature flags and such) but this is alpha anyhow 😁 . One other thing I was wondering is the filter fields. It would be nice to have a limit (max returned) and an order (asc, desc) for the timestamp field on it. Can I just add those fields to the database crate filter struct (non breaking with defaults)? |
Awesome, thank you!
There is already a |
Ah yes, sorry I meant |
Ok, thanks. I'll evaluate to revert the commit where I remove the For now I would say to extend the |
I added db specific migrations and generated schema (mappers) but no NostrDb traits impl for now. The PG implementation is now in its own module. After testing around with the feature flags I came to the conclusion that all queries need to be built completely generic (db backend seeps into connection and model mapping so the I an O of it 😁). My idea is to do a generic impl. for both Mysql and Sqlite and then migrate the PG version to it as well. |
@@ -0,0 +1,27 @@ | |||
-- The actual event data | |||
CREATE TABLE events ( | |||
id VARCHAR(64) PRIMARY KEY, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would store the 32-byte array here, instead of the hex. The same for the pubkey and signature (64-byte array), also in the other schemas. What do your think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll have to check whether there is support for binary indexes in all dbs and if there are any performance penalties. First look seem to be doable. Debugging the data (with other sql clients) will get a bit harder though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding the debugging in SQL clients: I know some clients display the bytes as hex, but not sure if all. I've tried DBeaver and JetBrains Database tool, and both display the event ID and public key BLOBs as hex.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes at least PG is storing small binaries as hex values anyhow. I have dropped the signature column and set the column types to be binary. Testing with PG seems to have no issues for the other backends I'll have to check when I add the impls.
crates/nostr-sqldb/migrations/sqlite/2025-04-11-095120_events/up.sql
Outdated
Show resolved
Hide resolved
This implements a basic driver for using Postgres, SQLite or MySQL as storage engine for nostr-database. Uses async Diesel as driver and Diesel migrations to set up the schema. Pull-Request: #835 Co-authored-by: Yuki Kishimoto <yukikishimoto@protonmail.com> Signed-off-by: Yuki Kishimoto <yukikishimoto@protonmail.com>
Thanks for the changes. I tested it locally and for now I prefer to not merge it in |
Squashed and moved to |
Description
Implements a basic driver for using Postgres as storage engine for nostr-database. Uses async Diesel as driver and Diesel migrations to setup the schema.
Checklist
just precommit
orjust check
before committing