generated from Patagia/template-nix
Compare commits
1 commit
02d3730119
...
13819278fe
Author | SHA1 | Date | |
---|---|---|---|
13819278fe |
7 changed files with 77 additions and 23 deletions
8
.cargo/audit.toml
Normal file
8
.cargo/audit.toml
Normal file
|
@ -0,0 +1,8 @@
|
|||
[advisories]
|
||||
ignore = [
|
||||
# Advisory about a vulnerability in rsa, which we don't use, but comes via sqlx due
|
||||
# to a bug in cargo. For context, see:
|
||||
# https://github.com/launchbadge/sqlx/issues/2911
|
||||
# and https://github.com/rust-lang/cargo/issues/10801
|
||||
"RUSTSEC-2023-0071"
|
||||
]
|
46
controller/.sqlx/query-843923b9a0257cf80f1dff554e7dc8fdfc05f489328e8376513124dfb42996e3.json
generated
Normal file
46
controller/.sqlx/query-843923b9a0257cf80f1dff554e7dc8fdfc05f489328e8376513124dfb42996e3.json
generated
Normal file
|
@ -0,0 +1,46 @@
|
|||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "SELECT * FROM users WHERE id = $1",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "id",
|
||||
"type_info": "Uuid"
|
||||
},
|
||||
{
|
||||
"ordinal": 1,
|
||||
"name": "name",
|
||||
"type_info": "Varchar"
|
||||
},
|
||||
{
|
||||
"ordinal": 2,
|
||||
"name": "time_deleted",
|
||||
"type_info": "Timestamptz"
|
||||
},
|
||||
{
|
||||
"ordinal": 3,
|
||||
"name": "time_created",
|
||||
"type_info": "Timestamptz"
|
||||
},
|
||||
{
|
||||
"ordinal": 4,
|
||||
"name": "time_modified",
|
||||
"type_info": "Timestamptz"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Uuid"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "843923b9a0257cf80f1dff554e7dc8fdfc05f489328e8376513124dfb42996e3"
|
||||
}
|
|
@ -15,7 +15,9 @@ schemars.workspace = true
|
|||
serde.workspace = true
|
||||
slog-async.workspace = true
|
||||
slog.workspace = true
|
||||
sqlx = { version = "0.8.3", features = ["postgres", "runtime-tokio", "tls-rustls", "time", "uuid"] }
|
||||
sqlx = { version = "0.8.3", default-features = false, features = [
|
||||
"macros", "postgres", "runtime-tokio", "tls-rustls", "time", "uuid"
|
||||
] }
|
||||
tokio.workspace = true
|
||||
trace-request = { path = "../trace-request" }
|
||||
tracing-slog.workspace = true
|
||||
|
|
|
@ -30,12 +30,12 @@ struct Cli {
|
|||
)]
|
||||
log_stderr: bool,
|
||||
|
||||
#[arg(
|
||||
long = "listen-address",
|
||||
default_value = "0.0.0.0:9474",
|
||||
env = "LISTEN_ADDRESS"
|
||||
)]
|
||||
listen_address: String,
|
||||
#[arg(
|
||||
long = "listen-address",
|
||||
default_value = "0.0.0.0:9474",
|
||||
env = "LISTEN_ADDRESS"
|
||||
)]
|
||||
listen_address: String,
|
||||
|
||||
#[arg(
|
||||
long = "database-url",
|
||||
|
@ -66,7 +66,11 @@ async fn main() -> Result<()> {
|
|||
|
||||
let database_url = args.database_url.unwrap();
|
||||
|
||||
tracing::info!(database_url, listen_address=args.listen_address, "Starting server");
|
||||
tracing::info!(
|
||||
database_url,
|
||||
listen_address = args.listen_address,
|
||||
"Starting server"
|
||||
);
|
||||
|
||||
let pg = PgPool::connect(&database_url).await?;
|
||||
|
||||
|
|
|
@ -5,9 +5,7 @@ pub struct ControllerContext {
|
|||
}
|
||||
|
||||
impl ControllerContext {
|
||||
pub fn new(pg_pool : PgPool) -> ControllerContext {
|
||||
ControllerContext {
|
||||
pg_pool
|
||||
}
|
||||
pub fn new(pg_pool: PgPool) -> ControllerContext {
|
||||
ControllerContext { pg_pool }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,10 +42,11 @@ pub(crate) async fn get_user_by_id(
|
|||
.fetch_one(&pg)
|
||||
.await
|
||||
.map_err(|e| match e {
|
||||
sqlx::Error::RowNotFound => HttpError::for_not_found(None, format!("User not found by id: {:?}", id)),
|
||||
err => HttpError::for_internal_error( format!("Error: {}", err))
|
||||
}
|
||||
)?;
|
||||
sqlx::Error::RowNotFound => {
|
||||
HttpError::for_not_found(None, format!("User not found by id: {:?}", id))
|
||||
}
|
||||
err => HttpError::for_internal_error(format!("Error: {}", err)),
|
||||
})?;
|
||||
|
||||
let user = User {
|
||||
id: rec.id,
|
||||
|
|
9
justfile
9
justfile
|
@ -84,18 +84,13 @@ dev-postgres-clean:
|
|||
dev-postgres-psql:
|
||||
podman exec -it patagia-postgres psql -U patagia
|
||||
|
||||
[group('controller')]
|
||||
[working-directory: 'controller']
|
||||
dev-controller-sqlx *ARGS:
|
||||
sqlx {{ARGS}}
|
||||
|
||||
[group('controller')]
|
||||
[working-directory: 'controller']
|
||||
dev-controller-db-migrate:
|
||||
sqlx migrate run
|
||||
cargo sqlx migrate run
|
||||
|
||||
[group('controller')]
|
||||
[working-directory: 'controller']
|
||||
dev-controller-db-reset:
|
||||
sqlx db reset -y
|
||||
cargo sqlx db reset -y
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue