emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/emacsql 5e2ab842f7 139/427: Add foreign key test.


From: ELPA Syncer
Subject: [nongnu] elpa/emacsql 5e2ab842f7 139/427: Add foreign key test.
Date: Tue, 13 Dec 2022 02:59:36 -0500 (EST)

branch: elpa/emacsql
commit 5e2ab842f7be6fdee017004a686d8ac93e964adf
Author: Christopher Wellons <wellons@nullprogram.com>
Commit: Christopher Wellons <wellons@nullprogram.com>

    Add foreign key test.
---
 emacsql-tests.el | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/emacsql-tests.el b/emacsql-tests.el
index 8eb8113805..c1f4542725 100644
--- a/emacsql-tests.el
+++ b/emacsql-tests.el
@@ -151,6 +151,7 @@
      "LIMIT 4, 30;")))
 
 (ert-deftest emacsql-system ()
+  "A short test that fully interacts with SQLite."
   (should-not (emacsql-sqlite3-unavailable-p))
   (emacsql-with-connection (db nil)
     (emacsql db [:create-table foo [x]])
@@ -159,6 +160,25 @@
     (should (equal (emacsql db [:select * :from foo])
                    '((1) (2) (3))))))
 
+(ert-deftest emacsql-foreign-system ()
+  "Tests that foreign keys work properly through Emacsql."
+  (emacsql-with-connection (db nil)
+    (emacsql-thread db
+      [:pragma (= foreign_keys on)]
+      [:create-table person [(id integer :primary) name]]
+      [:create-table likes ([(personid integer) color]
+                            :foreign (personid person id :on-delete :cascade))]
+      [:replace :into person :values ([0 "Chris"] [1 "Jeff"])])
+    (should (equal (emacsql db [:select * :from person :order-by id])
+                   '((0 "Chris") (1 "Jeff"))))
+    (emacsql db [:insert :into likes :values ([0 red] [0 yellow] [1 yellow])])
+    (should (equal (emacsql db [:select * :from likes
+                                        :order-by [personid color]])
+                   '((0 red) (0 yellow) (1 yellow))))
+    (emacsql db [:delete :from person :where (= id 0)])
+    (should (equal (emacsql db [:select * :from likes])
+                   '((1 yellow))))))
+
 (provide 'emacsql-tests)
 
 ;;; emacsql-tests.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]