feat(pedm): SQL support#1292
Conversation
This PR defines the structure for supporting multiple database backends, as well as
accessing data from state/middleware, to the PEDM module.
- adds support for libSQL and Postgres as database backends
- libSQL is the default
- new config file for specifying the database and defining configuration
- introduces the `Database` trait
- required queries are defined in the `Database` trait
- per backend implementations are defined in the backend-specific
file, i.e., _libsql.rs_ or _pg.rs_
- introduces `LogLayer`, tower middleware for logging request and response
metadata
- introduces `AppState`
- the _elevate_temporary_ handler is updated to illustrate accessing data from state (DB connection) and from middleware (request
ID)
- policies moved from global `OnceLock` to `AppState`
- plays nice with Aide/OpenAPI generation
Let maintainers know that an action is required on their side
|
It was previously not updated because I had test crates in the workspace. But CI is failing. Test crates removed. This updates Cargo.lock.
| [[package]] | ||
| name = "rustls" | ||
| version = "0.22.4" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "bf4ef73721ac7bcd79b2b315da7779d8fc09718c6b3d2d1b2d94850eb8c18432" | ||
| dependencies = [ | ||
| "log", | ||
| "ring 0.17.14", | ||
| "rustls-pki-types", | ||
| "rustls-webpki 0.102.8", | ||
| "subtle", | ||
| "zeroize", | ||
| ] |
There was a problem hiding this comment.
issue: This is duplicating the rustls dependency. 0.22 is the older one.
| [[package]] | ||
| name = "hyper-rustls" | ||
| version = "0.27.3" | ||
| version = "0.25.0" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "399c78f9338483cb7e630c8474b07268983c6bd5acee012e4211f9f7bb21b070" |
There was a problem hiding this comment.
issue: hyper-rustls also got duplicated, with an older one.
Benoît Cortier (CBenoit)
left a comment
There was a problem hiding this comment.
Some suspicious changes in our dependency graph. I don’t expect everything to be fixable, but ideally we should avoid duplicating dependencies or downgrading dependencies. If there is no immediate solution, we will merge now and fix later.
| server = create_pipe(pipe_name)?; | ||
|
|
||
| let tower_service = make_service.call(&client).await?; | ||
| let tower_service = make_service.call(&client).await.unwrap(); // return type is Infallible |
There was a problem hiding this comment.
style: A better way of handling Infaillible is:
| let tower_service = make_service.call(&client).await.unwrap(); // return type is Infallible | |
| let Ok(tower_service) = make_service.call(&client).await; |
| error!(%error, "Failed to serve connection"); | ||
| error!(%e, "Failed to serve connection"); |
There was a problem hiding this comment.
|
|
||
| let mut server = create_pipe(pipe_name)?; | ||
|
|
||
| // log the server startup |
There was a problem hiding this comment.
|
|
||
| use super::{Database, DbError}; | ||
|
|
||
| pub(crate) struct PgPool(Pool<PostgresConnectionManager<NoTls>>); |
There was a problem hiding this comment.
question: Is it really fine to use the "NoTls" variant?
There was a problem hiding this comment.
I can add TLS support in the future.
Benoît Cortier (CBenoit)
left a comment
There was a problem hiding this comment.
Approving as discussed on Slack
This removes postgres as a default feature. The crate now builds with libsql, postgres, or both features enabled.
This PR defines the structure for supporting multiple database backends, as well as accessing data from state/middleware, to the PEDM module.
DatabasetraitDatabasetraitLogLayer, tower middleware for logging request and response metadataAppStateOnceLocktoAppState