Add PostgreSQL support for mint and wallet #878

Merged
crodas merged 12 commits from feature/pg-sql into main 2025-08-18 16:45:11 +00:00
crodas commented 2025-07-08 21:21:53 +00:00 (Migrated from github.com)

Description

This is a WIP branch to add PostgreSQL support, fixing #877.

This PR depends on #890

Approach

  • Introduce cdk-sql-base a generic abstraction on top of any SQL database for the mint and the wallet
    • Rename cdk-sqlite into this crate.
    • Unify the statement.
    • Add a simple placeholder parser, supporting named arguments, but let the database driver to use positional placeholder, in whatever format they need. Make it work with bind and bind_vec.
    • Add custom migration for database vendor name, or migrations that applies to all.
    • Add cache for the placeholder parsed list
  • Make cdk-sqlite use cdk-sql-base
  • Add cdk-postgres

Notes to the reviewers


Suggested CHANGELOG Updates

CHANGED

ADDED

REMOVED

FIXED


Checklist

### Description This is a WIP branch to add PostgreSQL support, fixing #877. This PR depends on #890 #### Approach * [x] Introduce `cdk-sql-base` a generic abstraction on top of any SQL database for the mint and the wallet * [x] Rename `cdk-sqlite` into this crate. * [x] Unify the statement. * [x] Add a simple placeholder parser, supporting named arguments, but let the database driver to use positional placeholder, in whatever format they need. Make it work with `bind` and `bind_vec`. * [x] Add custom migration for database vendor name, or migrations that applies to all. * [ ] Add cache for the placeholder parsed list * [x] Make `cdk-sqlite` use `cdk-sql-base` * [ ] Add `cdk-postgres` ----- ### Notes to the reviewers <!-- In this section you can include notes directed to the reviewers, like explaining why some parts of the PR were done in a specific way --> ----- ### Suggested [CHANGELOG](https://github.com/cashubtc/cdk/blob/main/CHANGELOG.md) Updates <!-- Please do not edit the actual changelog but note what you changed here. --> #### CHANGED #### ADDED #### REMOVED #### FIXED ---- ### Checklist * [ ] I followed the [code style guidelines](https://github.com/cashubtc/cdk/blob/main/CODE_STYLE.md) * [ ] I ran `just final-check` before committing
crodas (Migrated from github.com) reviewed 2025-08-06 15:33:46 +00:00
@ -156,6 +157,23 @@ async fn setup_database(
let keystore: Arc<dyn MintKeysDatabase<Err = cdk_database::Error> + Send + Sync> = db;
crodas (Migrated from github.com) commented 2025-08-06 15:33:46 +00:00

rename to PG_DB_URL or fail.

rename to PG_DB_URL or fail.
thesimplekid commented 2025-08-11 09:35:20 +00:00 (Migrated from github.com)

If we add cargo update -p native-tls --precise 0.2.13 to the msrv shell it seems like the msrv is met.

If we add `cargo update -p native-tls --precise 0.2.13` to the msrv shell it seems like the msrv is met.
thesimplekid (Migrated from github.com) reviewed 2025-08-11 12:06:33 +00:00
@ -0,0 +1,155 @@
use cdk_common::database::Error;
thesimplekid (Migrated from github.com) commented 2025-08-11 11:42:27 +00:00
pub async fn pg_pluck(conn: &Client, statement: Statement) -> Result<Option<Column>, Error> {

typo?

```suggestion pub async fn pg_pluck(conn: &Client, statement: Statement) -> Result<Option<Column>, Error> { ``` typo?
thesimplekid commented 2025-08-11 12:20:48 +00:00 (Migrated from github.com)

Can we split 5f9b0b53dd3e9531e19bb22c6872f85bc305cb0d into its own pr I want to review that more carefully. Other then that I think it looks pretty good.

Can we split 5f9b0b53dd3e9531e19bb22c6872f85bc305cb0d into its own pr I want to review that more carefully. Other then that I think it looks pretty good.
thesimplekid (Migrated from github.com) reviewed 2025-08-18 09:37:08 +00:00
thesimplekid commented 2025-08-18 15:19:08 +00:00 (Migrated from github.com)
ACK 2b56063e472611c06007a73a78915e22944f3d55
asmogo commented 2025-08-18 16:41:39 +00:00 (Migrated from github.com)

Successfully tested github.com/cashubtc/cdk@2b56063e47 with psql and crdb.

LGTM.

Successfully tested https://github.com/cashubtc/cdk/commit/2b56063e472611c06007a73a78915e22944f3d55 with `psql` and `crdb`. LGTM.
thesimplekid (Migrated from github.com) approved these changes 2025-08-18 16:44:56 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cashubtc/cdk!878
No description provided.