feat: db: delete submission
This commit is contained in:
parent
bbc00e7c3b
commit
063b2f4b8f
2 changed files with 115 additions and 1 deletions
|
@ -1,3 +1,90 @@
|
||||||
{
|
{
|
||||||
"db": "PostgreSQL"
|
"db": "PostgreSQL",
|
||||||
|
"657a97c81a7bae97b22a5bc7e297978acc2c7fa3859aa8adffc2b6976aafde82": {
|
||||||
|
"describe": {
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"name": "value",
|
||||||
|
"ordinal": 0,
|
||||||
|
"type_info": "Jsonb"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "time",
|
||||||
|
"ordinal": 1,
|
||||||
|
"type_info": "Timestamptz"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "id",
|
||||||
|
"ordinal": 2,
|
||||||
|
"type_info": "Int4"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"nullable": [
|
||||||
|
true,
|
||||||
|
false,
|
||||||
|
false
|
||||||
|
],
|
||||||
|
"parameters": {
|
||||||
|
"Left": [
|
||||||
|
"Text",
|
||||||
|
"Text",
|
||||||
|
"Int8"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"query": "\n SELECT\n value, time, ID\n FROM\n forms_submissions\n WHERE\n website_id = (SELECT ID from forms_websites WHERE hostname = $1)\n AND\n website_path = $2\n LIMIT 50 OFFSET $3\n "
|
||||||
|
},
|
||||||
|
"d104afb356962d24a0f950243db587a5bebeeb43edcac36da7eebe0ed3b27f5e": {
|
||||||
|
"describe": {
|
||||||
|
"columns": [],
|
||||||
|
"nullable": [],
|
||||||
|
"parameters": {
|
||||||
|
"Left": [
|
||||||
|
"Varchar",
|
||||||
|
"Jsonb",
|
||||||
|
"Timestamptz",
|
||||||
|
"Text"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"query": "\n INSERT INTO forms_submissions (website_path, value, time, website_id)\n VALUES ($1, $2, $3, (SELECT ID from forms_websites WHERE hostname = $4));\n "
|
||||||
|
},
|
||||||
|
"d184df863185d97345d5de3b80823312053a7a38316fd8b3c8fdd32d9a29644a": {
|
||||||
|
"describe": {
|
||||||
|
"columns": [],
|
||||||
|
"nullable": [],
|
||||||
|
"parameters": {
|
||||||
|
"Left": [
|
||||||
|
"Varchar"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"query": "INSERT INTO forms_websites (hostname) VALUES ($1) ON CONFLICT DO NOTHING;"
|
||||||
|
},
|
||||||
|
"d548953611b4fccb07ef22cb185deac69e4feb79864fcc98f2dc868298587315": {
|
||||||
|
"describe": {
|
||||||
|
"columns": [],
|
||||||
|
"nullable": [],
|
||||||
|
"parameters": {
|
||||||
|
"Left": [
|
||||||
|
"Text"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"query": "DELETE FROM forms_websites WHERE hostname = ($1)"
|
||||||
|
},
|
||||||
|
"f4363f976c9321158b58ad9f5a8e8233957d3e139112b84aa5db23510a3ca334": {
|
||||||
|
"describe": {
|
||||||
|
"columns": [],
|
||||||
|
"nullable": [],
|
||||||
|
"parameters": {
|
||||||
|
"Left": [
|
||||||
|
"Int4",
|
||||||
|
"Text",
|
||||||
|
"Text"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"query": "DELETE\n FROM\n forms_submissions\n WHERE\n ID = $1\n AND\n website_path = $2\n AND\n website_id = (SELECT ID FROM forms_websites WHERE hostname = $3);\n "
|
||||||
|
}
|
||||||
}
|
}
|
27
src/db.rs
27
src/db.rs
|
@ -171,6 +171,29 @@ impl Database {
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// delete form submission
|
||||||
|
pub async fn delete_submission(&self, id: i32, host: &str, path: &str) -> ServiceResult<()> {
|
||||||
|
sqlx::query!(
|
||||||
|
"DELETE
|
||||||
|
FROM
|
||||||
|
forms_submissions
|
||||||
|
WHERE
|
||||||
|
ID = $1
|
||||||
|
AND
|
||||||
|
website_path = $2
|
||||||
|
AND
|
||||||
|
website_id = (SELECT ID FROM forms_websites WHERE hostname = $3);
|
||||||
|
",
|
||||||
|
id,
|
||||||
|
path,
|
||||||
|
host
|
||||||
|
)
|
||||||
|
.execute(&self.pool)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
@ -235,6 +258,10 @@ mod tests {
|
||||||
&serde_json::Value::default(),
|
&serde_json::Value::default(),
|
||||||
subs[0].value.as_ref().unwrap()
|
subs[0].value.as_ref().unwrap()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
db.delete_submission(subs[0].id, url, path).await.unwrap();
|
||||||
|
let subs = db.get_form_submissions(0, url, path).await.unwrap();
|
||||||
|
assert!(subs.is_empty());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue