-
Notifications
You must be signed in to change notification settings - Fork 19
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
feat(pedm): SQL support #1292
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: This is duplicating the rustls dependency. 0.22 is the older one.
Cargo.lock
Outdated
[[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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: hyper-rustls also got duplicated, with an older one.
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.
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.
loop { | ||
server.connect().await?; | ||
let client = server; | ||
|
||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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; |
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.
Implemented in e99d392.
error!(%error, "Failed to serve connection"); | ||
error!(%e, "Failed to serve connection"); |
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.
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.
Implemented in baf5f47.
|
||
let mut make_service = app.into_make_service_with_connect_info::<RawNamedPipeConnectInfo>(); | ||
|
||
let mut server = create_pipe(pipe_name)?; | ||
|
||
// log the server startup |
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.
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.
Implemented in cd67021.
|
||
use super::{Database, DbError}; | ||
|
||
pub(crate) struct PgPool(Pool<PostgresConnectionManager<NoTls>>); |
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.
question: Is it really fine to use the "NoTls" variant?
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 can add TLS support in the future.
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.
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.
Database
traitDatabase
traitLogLayer
, tower middleware for logging request and response metadataAppState
OnceLock
toAppState