initial commit
[squeep-indie-auther] / src / db / sqlite / sql / scope-upsert.sql
diff --git a/src/db/sqlite/sql/scope-upsert.sql b/src/db/sqlite/sql/scope-upsert.sql
new file mode 100644 (file)
index 0000000..cb2770f
--- /dev/null
@@ -0,0 +1,16 @@
+--
+INSERT INTO scope (
+       scope,
+       description,
+       application,
+       is_manually_added
+) VALUES (
+       :scope,
+       CASE WHEN :application IS NULL THEN '' ELSE :application END,
+       CASE WHEN :description IS NULL THEN '' ELSE :description END,
+       COALESCE(:manuallyAdded, false)
+) ON CONFLICT (scope) DO UPDATE
+SET
+       application = COALESCE(:application, EXCLUDED.application),
+       description = COALESCE(:description, EXCLUDED.description),
+       is_manually_added = EXCLUDED.is_manually_added OR COALESCE(:manuallyAdded, false)