branch: elpa/emacsql commit 0f0840ffbf576a49783eefa2a4b7bb916952349b Author: Christopher Wellons <well...@nullprogram.com> Commit: Christopher Wellons <well...@nullprogram.com>
Add :default column constraint. --- README.md | 5 +++-- emacsql-tests.el | 4 ++++ emacsql.el | 2 ++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a82a88c6cc..af7699f187 100644 --- a/README.md +++ b/README.md @@ -58,8 +58,9 @@ symbol or it can include constraints, such as type and uniqueness. Because Emacsql stores entire lisp objects as values, the only relevant types are `integer`, `float`, and `object` (default). -Additional constraints include `:primary` (aka `PRIMARY KEY`), -`:unique` (aka `UNIQUE`), `:non-nil` (aka `NOT NULL`). +Additional columns constraints include `:primary` (aka `PRIMARY KEY`), +`:unique` (aka `UNIQUE`), `:non-nil` (aka `NOT NULL`), `:default` (aka +`DEFAULT`). ```el ;; Example schema: diff --git a/emacsql-tests.el b/emacsql-tests.el index 3d048e3849..dac5793f89 100644 --- a/emacsql-tests.el +++ b/emacsql-tests.el @@ -76,6 +76,10 @@ "CREATE TABLE foo (a, b, c);") ([:create-table (:temporary :if-not-exists x) [y]] '() "CREATE TEMPORARY TABLE IF NOT EXISTS x (y);") + ([:create-table foo [(a :default 10)]] '() + "CREATE TABLE foo (a DEFAULT 10);") + ([:create-table foo [(a :primary :non-nil) b]] '() + "CREATE TABLE foo (a PRIMARY KEY NOT NULL, b);") ([:drop-table $1] '(foo) "DROP TABLE foo;"))) diff --git a/emacsql.el b/emacsql.el index 71206e71ab..8861f25ec7 100644 --- a/emacsql.el +++ b/emacsql.el @@ -275,6 +275,8 @@ CONN-SPEC is a connection specification like the call to (:primary (push "PRIMARY KEY" output)) (:non-nil (push "NOT NULL" output)) (:unique (push "UNIQUE" output)) + (:default (push "DEFAULT" output) + (push (emacsql-escape-value (pop column)) output)) (integer (setf type "INTEGER")) (float (setf type "REAL")) (object (setf type "TEXT"))