fix: sqlite update record on unique constraint violation

This commit is contained in:
Aravinth Manivannan 2025-03-20 13:04:56 +05:30
parent 21b60a4660
commit a6216e14bc
Signed by: realaravinth
GPG key ID: F8F50389936984FF
2 changed files with 55 additions and 55 deletions

View file

@ -18,16 +18,6 @@
},
"query": "SELECT\n starchart_introducer.instance_url\n FROM \n starchart_federated_mini_index\n INNER JOIN\n starchart_introducer\n ON\n starchart_introducer.ID = starchart_instance \n WHERE\n mini_index MATCH $1"
},
"069a127ffb1062321bba5a915a4ead3e0bbe4dabf6e0f684d8cc6a6d8a68ad5b": {
"describe": {
"columns": [],
"nullable": [],
"parameters": {
"Right": 4
}
},
"query": "INSERT OR IGNORE INTO fts_repositories ( name, description, website, html_url ) \n VALUES ( $1, $2, $3, $4 );"
},
"0b179588df37779f563f0ad8c43e920a8bc22b3eed682778cef9dd05608f9691": {
"describe": {
"columns": [
@ -104,6 +94,26 @@
},
"query": "SELECT html_url, profile_photo_html_url, imported FROM starchart_users WHERE username = $1 AND \n hostname_id = (SELECT ID FROM starchart_forges WHERE hostname = $2)"
},
"1f47bff0270cfb9d58972ecf6ae36f348d9f605a40a8669ce2908b50a3aac735": {
"describe": {
"columns": [],
"nullable": [],
"parameters": {
"Right": 4
}
},
"query": "INSERT OR REPLACE INTO fts_repositories ( name, description, website, html_url ) \n VALUES ( $1, $2, $3, $4 );"
},
"2ac627ddd905bab19582037ca5e402ebaa268b61d94459e125644028d04e6dc2": {
"describe": {
"columns": [],
"nullable": [],
"parameters": {
"Right": 4
}
},
"query": "INSERT OR REPLACE INTO starchart_forges\n (hostname, verified_on, forge_type, starchart_instance)\n VALUES (\n $1,\n $2,\n (SELECT ID FROM starchart_forge_type WHERE name = $3),\n (SELECT ID FROM starchart_introducer WHERE instance_url = $4)\n )"
},
"2afb17ba3753aa440465a836b46b7a1466f25791cfc4d0acdd38bc2755ae3e86": {
"describe": {
"columns": [
@ -140,16 +150,6 @@
},
"query": "SELECT ID FROM starchart_forge_type WHERE name = $1"
},
"338fb30307071e6df9efee6a68697c60e579d7b2332630bce401c0e7186a642a": {
"describe": {
"columns": [],
"nullable": [],
"parameters": {
"Right": 7
}
},
"query": "INSERT INTO \n starchart_users (\n hostname_id, username, html_url,\n profile_photo_html_url, added_on, last_crawl_on, imported\n ) \n VALUES (\n (SELECT ID FROM starchart_forges WHERE hostname = $1), $2, $3, $4, $5, $6, $7)"
},
"364c8e3d147318b864fd28ad284f225aaace9479b5cf0428fb97f0e5689e248d": {
"describe": {
"columns": [],
@ -224,6 +224,16 @@
},
"query": "SELECT\n hostname,\n last_crawl_on,\n starchart_introducer.instance_url,\n starchart_forge_type.name\n FROM\n starchart_forges\n INNER JOIN\n starchart_forge_type\n ON\n starchart_forges.forge_type = starchart_forge_type.id\n LEFT JOIN\n starchart_introducer\n ON\n starchart_introducer.ID = starchart_forges.starchart_instance\n WHERE \n starchart_forges.imported = 0\n ORDER BY\n starchart_forges.ID\n LIMIT $1 OFFSET $2;\n "
},
"6c6a24873ae0053df5b875a35ed8c605e73c9718951b87140d2cada093ec4cf6": {
"describe": {
"columns": [],
"nullable": [],
"parameters": {
"Right": 9
}
},
"query": "INSERT OR REPLACE INTO \n starchart_repositories (\n hostname_id, owner_id, name, description, html_url, website, created,\n last_crawl, imported\n )\n VALUES (\n (SELECT ID FROM starchart_forges WHERE hostname = $1),\n (SELECT ID FROM starchart_users WHERE username = $2),\n $3, $4, $5, $6, $7, $8, $9\n );"
},
"6f5ca3d71a541eb6f33e37a5889c048536ab6ad7e81a6236d73aa71433c13717": {
"describe": {
"columns": [],
@ -234,16 +244,6 @@
},
"query": "INSERT OR IGNORE INTO starchart_project_topics ( name ) VALUES ( $1 );"
},
"74fb3a1ae4f339b5371a6872e6eb4ed7c1f5968dac70de1639454c394a05cb38": {
"describe": {
"columns": [],
"nullable": [],
"parameters": {
"Right": 4
}
},
"query": "INSERT INTO starchart_forges\n (hostname, verified_on, forge_type, starchart_instance)\n VALUES\n (\n $1, $2,\n (SELECT ID FROM starchart_forge_type WHERE name = $3),\n $4)"
},
"7590630f5fe7e05014b70ac0047f9b6c724b88e35e1b1306fb89760612929d55": {
"describe": {
"columns": [],
@ -424,6 +424,16 @@
},
"query": "SELECT name FROM starchart_project_topics ORDER BY ID LIMIT $1 OFFSET $2;"
},
"a754fb4bcdd227f3ab440c5600a534dcabde3e75ea242a530d6aa12c7502c88e": {
"describe": {
"columns": [],
"nullable": [],
"parameters": {
"Right": 7
}
},
"query": "INSERT OR REPLACE INTO \n starchart_users (\n hostname_id, username, html_url,\n profile_photo_html_url, added_on, last_crawl_on, imported\n ) \n VALUES (\n (SELECT ID FROM starchart_forges WHERE hostname = $1), $2, $3, $4, $5, $6, $7)"
},
"a81dd4b5df666e22fac211092e7b8425d838dd9023aa2b17659352f30831944d": {
"describe": {
"columns": [
@ -442,16 +452,6 @@
},
"query": "SELECT ID FROM starchart_users WHERE username = $1 AND \n hostname_id = (SELECT ID FROM starchart_forges WHERE hostname = $2)"
},
"a912406491a4e9ea1bbf8a3d0003e948a24df7f101c490aca395f5b86ec64d00": {
"describe": {
"columns": [],
"nullable": [],
"parameters": {
"Right": 4
}
},
"query": "INSERT OR IGNORE INTO starchart_forges\n (hostname, verified_on, forge_type, starchart_instance)\n VALUES (\n $1,\n $2,\n (SELECT ID FROM starchart_forge_type WHERE name = $3),\n (SELECT ID FROM starchart_introducer WHERE instance_url = $4)\n )"
},
"ae9295f46da1753fe91a633b5738533084005ad32915c19635f896c454284b6b": {
"describe": {
"columns": [
@ -522,16 +522,6 @@
},
"query": "INSERT OR IGNORE INTO\n starchart_imported_starcharts (starchart_instance)\n VALUES ((SELECT ID FROM starchart_introducer WHERE instance_url = $1));"
},
"ca22e5f6e7065cf2d4ffdbfac0084f9871de8cd9073d470cbf7eac2de2a73c47": {
"describe": {
"columns": [],
"nullable": [],
"parameters": {
"Right": 9
}
},
"query": "INSERT INTO \n starchart_repositories (\n hostname_id, owner_id, name, description, html_url, website, created,\n last_crawl, imported\n )\n VALUES (\n (SELECT ID FROM starchart_forges WHERE hostname = $1),\n (SELECT ID FROM starchart_users WHERE username = $2),\n $3, $4, $5, $6, $7, $8, $9\n );"
},
"d22d18f0c2b49a570ac95e1af5ba398b3d1c7a1a5a6780d6dc646077e466714c": {
"describe": {
"columns": [
@ -690,6 +680,16 @@
},
"query": "SELECT word FROM starchart_mini_index"
},
"fc32b8d0e5599dcc1ceed4127ca860d09754dd6d1fe558fbe5c7f4086c901b8f": {
"describe": {
"columns": [],
"nullable": [],
"parameters": {
"Right": 4
}
},
"query": "INSERT OR REPLACE INTO starchart_forges\n (hostname, verified_on, forge_type, starchart_instance)\n VALUES\n (\n $1, $2,\n (SELECT ID FROM starchart_forge_type WHERE name = $3),\n $4)"
},
"fdf87490759150d528139b13eb1a28532b5bebb546ade00bcb6a7d648abcd445": {
"describe": {
"columns": [],

View file

@ -160,7 +160,7 @@ impl Database {
return Ok(());
}
sqlx::query!(
"INSERT OR IGNORE INTO fts_repositories ( name, description, website, html_url )
"INSERT OR REPLACE INTO fts_repositories ( name, description, website, html_url )
VALUES ( $1, $2, $3, $4 );",
name,
description,
@ -313,7 +313,7 @@ impl SCDatabase for Database {
let forge_type = f.forge_type.to_str();
if let Some(instance_url) = f.starchart_url {
sqlx::query!(
"INSERT OR IGNORE INTO starchart_forges
"INSERT OR REPLACE INTO starchart_forges
(hostname, verified_on, forge_type, starchart_instance)
VALUES (
$1,
@ -331,7 +331,7 @@ impl SCDatabase for Database {
.map_err(map_register_err)?;
} else {
sqlx::query!(
"INSERT INTO starchart_forges
"INSERT OR REPLACE INTO starchart_forges
(hostname, verified_on, forge_type, starchart_instance)
VALUES
(
@ -491,7 +491,7 @@ impl SCDatabase for Database {
let now = now_unix_time_stamp();
let url = db_core::clean_url(&u.url);
sqlx::query!(
"INSERT INTO
"INSERT OR REPLACE INTO
starchart_users (
hostname_id, username, html_url,
profile_photo_html_url, added_on, last_crawl_on, imported
@ -607,7 +607,7 @@ impl SCDatabase for Database {
let now = now_unix_time_stamp();
let url = db_core::clean_url(&r.url);
sqlx::query!(
"INSERT INTO
"INSERT OR REPLACE INTO
starchart_repositories (
hostname_id, owner_id, name, description, html_url, website, created,
last_crawl, imported