diff --git a/.sqlx/query-718110e13b155eb56cac3f21e1db3b61db1b2d8ba26c160e38e739fd18caa0fc.json b/.sqlx/query-718110e13b155eb56cac3f21e1db3b61db1b2d8ba26c160e38e739fd18caa0fc.json new file mode 100644 index 000000000..9cbcbb35c --- /dev/null +++ b/.sqlx/query-718110e13b155eb56cac3f21e1db3b61db1b2d8ba26c160e38e739fd18caa0fc.json @@ -0,0 +1,38 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT * FROM sandbox_overrides", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "crate_name", + "type_info": "Varchar" + }, + { + "ordinal": 1, + "name": "max_memory_bytes", + "type_info": "Int8" + }, + { + "ordinal": 2, + "name": "timeout_seconds", + "type_info": "Int4" + }, + { + "ordinal": 3, + "name": "max_targets", + "type_info": "Int4" + } + ], + "parameters": { + "Left": [] + }, + "nullable": [ + false, + true, + true, + true + ] + }, + "hash": "718110e13b155eb56cac3f21e1db3b61db1b2d8ba26c160e38e739fd18caa0fc" +} diff --git a/.sqlx/query-a3920d6701d1a80f23562ee83682d82ff35a52eeaa93ed45a97adc5e559d3538.json b/.sqlx/query-a3920d6701d1a80f23562ee83682d82ff35a52eeaa93ed45a97adc5e559d3538.json new file mode 100644 index 000000000..87fe73890 --- /dev/null +++ b/.sqlx/query-a3920d6701d1a80f23562ee83682d82ff35a52eeaa93ed45a97adc5e559d3538.json @@ -0,0 +1,40 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT * FROM sandbox_overrides WHERE crate_name = $1", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "crate_name", + "type_info": "Varchar" + }, + { + "ordinal": 1, + "name": "max_memory_bytes", + "type_info": "Int8" + }, + { + "ordinal": 2, + "name": "timeout_seconds", + "type_info": "Int4" + }, + { + "ordinal": 3, + "name": "max_targets", + "type_info": "Int4" + } + ], + "parameters": { + "Left": [ + "Text" + ] + }, + "nullable": [ + false, + true, + true, + true + ] + }, + "hash": "a3920d6701d1a80f23562ee83682d82ff35a52eeaa93ed45a97adc5e559d3538" +} diff --git a/src/db/overrides.rs b/src/db/overrides.rs index 3d1259e1a..ab23c8284 100644 --- a/src/db/overrides.rs +++ b/src/db/overrides.rs @@ -1,6 +1,5 @@ use crate::error::Result; use futures_util::stream::TryStreamExt; -use sqlx::{postgres::PgRow, FromRow, Row}; use std::time::Duration; #[derive(Default, Debug, Clone, Copy, Eq, PartialEq)] @@ -10,42 +9,33 @@ pub struct Overrides { pub timeout: Option, } -impl FromRow<'_, PgRow> for Overrides { - fn from_row(row: &PgRow) -> sqlx::Result { - Ok(Self { - memory: row - .get::, _>("max_memory_bytes") - .map(|i| i as usize), - targets: row.get::, _>("max_targets").map(|i| i as usize), - timeout: row - .get::, _>("timeout_seconds") - .map(|i| Duration::from_secs(i as u64)), - }) - } +macro_rules! row_to_overrides { + ($row:expr) => {{ + Overrides { + memory: $row.max_memory_bytes.map(|i| i as usize), + targets: $row.max_targets.map(|i| i as usize), + timeout: $row.timeout_seconds.map(|i| Duration::from_secs(i as u64)), + } + }}; } impl Overrides { pub async fn all(conn: &mut sqlx::PgConnection) -> Result> { - Ok(sqlx::query("SELECT * FROM sandbox_overrides") + Ok(sqlx::query!("SELECT * FROM sandbox_overrides") .fetch(conn) - .map_ok(|row| { - ( - row.get("crate_name"), - Overrides::from_row(&row) - .expect("this is fine because we never return Err(_) in from_row"), - ) - }) + .map_ok(|row| (row.crate_name, row_to_overrides!(row))) .try_collect() .await?) } pub async fn for_crate(conn: &mut sqlx::PgConnection, krate: &str) -> Result> { - Ok( - sqlx::query_as("SELECT * FROM sandbox_overrides WHERE crate_name = $1") - .bind(krate) - .fetch_optional(conn) - .await?, + Ok(sqlx::query!( + "SELECT * FROM sandbox_overrides WHERE crate_name = $1", + krate ) + .fetch_optional(conn) + .await? + .map(|row| row_to_overrides!(row))) } pub async fn save(conn: &mut sqlx::PgConnection, krate: &str, overrides: Self) -> Result<()> {