branch: elpa/emacsql
commit d04ef64ce0f3415c4e4b6e34979935fa2dfa20a6
Author: Christopher Wellons <[email protected]>
Commit: Christopher Wellons <[email protected]>
Add IF NOT EXISTS and TEMPORARY to CREATE TABLE.
---
README.md | 1 +
emacsql.el | 14 +++++++++++---
2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/README.md b/README.md
index dfbf1a6438..77fea6ca74 100644
--- a/README.md
+++ b/README.md
@@ -116,6 +116,7 @@ Provides `CREATE TABLE`.
```el
[:create-table employees [name (id integer :primary) (salary float)]]
+[:create-table (:temporary :if-not-exists employees) ...]
```
#### :drop-table `<table>`
diff --git a/emacsql.el b/emacsql.el
index e946a29422..9335f45cbf 100644
--- a/emacsql.el
+++ b/emacsql.el
@@ -501,9 +501,17 @@ definitions for return from a `emacsql-defexpander'."
(combine (emacsql--expr expr))))
(emacsql-defexpander :create-table (table schema)
- (emacsql-with-vars "CREATE TABLE "
- (format "%s (%s)" (var table :identifier)
- (emacsql--schema-to-string schema))))
+ (emacsql-with-vars "CREATE "
+ (let (temporary if-not-exists name)
+ (dolist (item (if (listp table) table (list table)))
+ (cl-case item
+ (:if-not-exists (setf if-not-exists "IF NOT EXISTS"))
+ (:temporary (setf temporary "TEMPORARY"))
+ (otherwise (setf name (var item :identifier)))))
+ (let* ((items (list temporary "TABLE" if-not-exists name))
+ (spec (remove-if-not #'identity items)))
+ (format "%s (%s)" (mapconcat #'identity spec " ")
+ (emacsql--schema-to-string schema))))))
(emacsql-defexpander :drop-table (table)
(emacsql-with-vars "DROP TABLE "