add: developer pass

This commit is contained in:
trisua 2025-07-18 14:52:00 -04:00
parent 636ecce9f4
commit 02f3d08926
14 changed files with 355 additions and 101 deletions

View file

@ -147,6 +147,8 @@ impl AppData {
#[derive(Serialize, Deserialize, Debug, Clone)]
pub enum AppDataSelectQuery {
KeyIs(String),
KeyLike(String),
ValueLike(String),
LikeJson(String, String),
}
@ -154,11 +156,24 @@ impl Display for AppDataSelectQuery {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(&match self {
Self::KeyIs(k) => k.to_owned(),
Self::KeyLike(k) => k.to_owned(),
Self::ValueLike(v) => v.to_owned(),
Self::LikeJson(k, v) => format!("%\"{k}\":\"{v}\"%"),
})
}
}
impl AppDataSelectQuery {
pub fn selector(&self) -> String {
match self {
AppDataSelectQuery::KeyIs(_) => format!("k = $1"),
AppDataSelectQuery::KeyLike(_) => format!("k LIKE $1"),
AppDataSelectQuery::ValueLike(_) => format!("v LIKE $1"),
AppDataSelectQuery::LikeJson(_, _) => format!("v LIKE $1"),
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub enum AppDataSelectMode {
/// Select a single row (with offset).
@ -179,14 +194,14 @@ impl Display for AppDataSelectMode {
Self::One(offset) => format!("LIMIT 1 OFFSET {offset}"),
Self::Many(limit, offset) => {
format!(
"LIMIT {} OFFSET {offset}",
if *limit > 1024 { 1024 } else { *limit }
"ORDER BY k DESC LIMIT {} OFFSET {offset}",
if *limit > 24 { 24 } else { *limit }
)
}
Self::ManyJson(order_by_top_level_key, limit, offset) => {
format!(
"ORDER BY v::jsonb->>'{order_by_top_level_key}' DESC LIMIT {} OFFSET {offset}",
if *limit > 1024 { 1024 } else { *limit }
if *limit > 24 { 24 } else { *limit }
)
}
})