mirror of
https://github.com/aljazceru/cdk.git
synced 2025-12-18 21:25:09 +01:00
* Working on a better database abstraction After [this question in the chat](https://matrix.to/#/!oJFtttFHGfnTGrIjvD:matrix.cashu.space/$oJFtttFHGfnTGrIjvD:matrix.cashu.space/$I5ZtjJtBM0ctltThDYpoCwClZFlM6PHzf8q2Rjqmso8) regarding a database transaction within the same function, I realized a few design flaws in our SQL database abstraction, particularly regarding transactions. 1. Our upper abstraction got it right, where a transaction is bound with `&mut self`, so Rust knows how to handle its lifetime with' async/await'. 2. The raw database does not; instead, it returns &self, and beginning a transaction takes &self as well, which is problematic for Rust, but that's not all. It is fundamentally wrong. A transaction should take &mut self when beginning a transaction, as that connection is bound to a transaction and should not be returned to the pool. Currently, that responsibility lies with the implementor. If a mistake is made, a transaction could be executed in two or more connections. 3. The way a database is bound to our store layer is through a single struct, which may or may not internally utilize our connection pool. This is also another design flow, in this PR, a connection pool is owned, and to use a connection, it should be requested, and that connection is reference with mutable when beginning a transaction * Improve the abstraction with fewer generics As suggested by @thesimplekid * Add BEGIN IMMEDIATE for SQLite
CDK SQLite
ALPHA This library is in early development, the API will change and should be used with caution.
SQLite storage backend implementation for the Cashu Development Kit (CDK).
Features
The following crate feature flags are available:
| Feature | Default | Description |
|---|---|---|
wallet |
Yes | Enable cashu wallet features |
mint |
Yes | Enable cashu mint wallet features |
sqlcipher |
No | Enable encrypted database |
Installation
Add this to your Cargo.toml:
[dependencies]
cdk-sqlite = "*"
Minimum Supported Rust Version (MSRV)
This crate supports Rust version 1.75.0 or higher.
To build and test with the MSRV you will need to pin the below dependency versions:
cargo update -p half --precise 2.2.1
cargo update -p home --precise 0.5.5
cargo update -p tokio --precise 1.38.1
cargo update -p serde_with --precise 3.1.0
cargo update -p reqwest --precise 0.12.4
License
This project is licensed under the MIT License.