mirror of
https://github.com/aljazceru/cdk.git
synced 2025-12-25 16:44:46 +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
32 lines
937 B
TOML
32 lines
937 B
TOML
[package]
|
|
name = "cdk-sql-common"
|
|
version.workspace = true
|
|
edition.workspace = true
|
|
authors = ["CDK Developers"]
|
|
description = "Generic SQL storage backend for CDK"
|
|
license.workspace = true
|
|
homepage = "https://github.com/cashubtc/cdk"
|
|
repository = "https://github.com/cashubtc/cdk.git"
|
|
rust-version.workspace = true # MSRV
|
|
readme = "README.md"
|
|
|
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
|
[features]
|
|
default = ["mint", "wallet", "auth"]
|
|
mint = ["cdk-common/mint"]
|
|
wallet = ["cdk-common/wallet"]
|
|
auth = ["cdk-common/auth"]
|
|
|
|
[dependencies]
|
|
async-trait.workspace = true
|
|
cdk-common = { workspace = true, features = ["test"] }
|
|
bitcoin.workspace = true
|
|
thiserror.workspace = true
|
|
tracing.workspace = true
|
|
tokio.workspace = true
|
|
serde.workspace = true
|
|
serde_json.workspace = true
|
|
lightning-invoice.workspace = true
|
|
uuid.workspace = true
|
|
once_cell.workspace = true
|