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

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

[nongnu] elpa/emacsql a362a97c98 136/427: Add README section on foreign


From: ELPA Syncer
Subject: [nongnu] elpa/emacsql a362a97c98 136/427: Add README section on foreign keys.
Date: Tue, 13 Dec 2022 02:59:36 -0500 (EST)

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

    Add README section on foreign keys.
---
 README.md | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md
index 9a9c7764be..e58c86ce2b 100644
--- a/README.md
+++ b/README.md
@@ -63,7 +63,7 @@ allowed) types are `integer`, `float`, and `object` (default).
 Columns constraints include `:primary` (aka `PRIMARY KEY`), `:unique`,
 `:non-nil` (aka `NOT NULL`), `:default`, and `:check`.
 
-Table constraints can be `:primary`, `:unique`, and `:check`.
+Table constraints can be `:primary`, `:unique`, `:check`, and `:foreign`.
 
 ```el
 ;; No constraints schema with four columns:
@@ -77,6 +77,25 @@ Table constraints can be `:primary`, `:unique`, and `:check`.
  :unique [building room] :check ())
 ```
 
+Foreign keys are the most complex. Action triggers are `:on-delete`
+or `:on-update` and possible actions are `:set-nil`, `:set-default`,
+`:restrict`, `:cascade`. See [the SQLite documentation][foreign] for
+the details on what each of these means.
+
+`:foreign (<child-keys> <parent-table> <parent-keys> [<actions>])`.
+
+```el
+;; "subject" table
+[(id integer :primary) subject]
+
+;; "tag" table references subjects
+([(subjectid integer) tag]
+ :foreign (subjectid subject id :on-delete :cascade))
+```
+
+Put the keys in a vector if the reference is composite, but remember
+that the cardinality must match.
+
 ## Operators
 
 Emacsql currently supports the following expression operators, named
@@ -276,3 +295,4 @@ types. This is a high-performance database specifically for 
Emacs.
 
 [readable]: 
http://nullprogram.com/blog/2013/12/30/#almost_everything_prints_readably
 [stderr]: http://thread.gmane.org/gmane.comp.db.sqlite.general/85824
+[foreign]: http://www.sqlite.org/foreignkeys.html



reply via email to

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