INSERT with ON CONFLICT

This commit is contained in:
losfair 2022-10-01 18:36:35 +00:00
parent d1ed9883db
commit 99c66e273b

View file

@ -49,10 +49,13 @@ impl Database {
pub async fn store(&self, document_id: &str, document: &PersistedDocument) -> Result<()> {
let result = sqlx::query(
r#"
INSERT OR REPLACE INTO
INSERT INTO
document (id, text, language)
VALUES
($1, $2, $3)"#,
($1, $2, $3)
ON CONFLICT(id) DO UPDATE SET
text = excluded.text,
language = excluded.language"#,
)
.bind(document_id)
.bind(&document.text)