Procházet zdrojové kódy

INSERT with ON CONFLICT

losfair před 2 roky
rodič
revize
99c66e273b
1 změnil soubory, kde provedl 5 přidání a 2 odebrání
  1. 5 2
      rustpad-server/src/database.rs

+ 5 - 2
rustpad-server/src/database.rs

@@ -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)