branch: elpa/emacsql commit add06c47b90715394c615b3f5cdcea6c2f121019 Author: Christopher Wellons <well...@nullprogram.com> Commit: Christopher Wellons <well...@nullprogram.com>
Bring back :into for :replace (oops!). --- README.md | 15 ++++++++++++--- emacsql-tests.el | 4 ++-- emacsql.el | 19 +++++++++++-------- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 318906e58a..55654a5b91 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ shouldn't impact normal use of the database. (emacsql db [:create-table people [name (id integer :unique) (salary float)]]) ;; Insert some data: -(emacsql db [:insert-into people +(emacsql db [:insert :into people :values (["Jeff" 1000 60000.0] ["Susan" 1001 64000.0])]) ;; Query the database for results: @@ -160,9 +160,18 @@ Provides `GROUP BY`. [... :group-by name] ``` -#### :insert-into `<table>` +#### :insert, :replace -Provides `INSERT INTO`. +Provides `INSERT`, `REPLACE`. + +```el +[:insert :into ...] +[:replace :into ...] +``` + +#### :into `<table>` + +Provides `INTO`. ```el [:insert-into employees ...] diff --git a/emacsql-tests.el b/emacsql-tests.el index 2c81a4d18c..2138d3ec96 100644 --- a/emacsql-tests.el +++ b/emacsql-tests.el @@ -69,7 +69,7 @@ "UPDATE people SET id = 10;") (emacsql-tests-query [:select * :from people :where (in name $1)] '([FOO BAR]) "SELECT * FROM people WHERE name IN ('FOO', 'BAR');") - (emacsql-tests-query [:insert-into foo :values [nil $1]] '(10.1) + (emacsql-tests-query [:insert :into foo :values [nil $1]] '(10.1) "INSERT INTO foo VALUES (NULL, 10.1);") (emacsql-tests-query [:create-table (:temporary :if-not-exists x) [y]] '() "CREATE TEMPORARY TABLE IF NOT EXISTS x (y);")) @@ -78,7 +78,7 @@ (emacsql-with-connection (db nil) (emacsql db [:create-table foo [x]]) (should-error (emacsql db [:create-table foo [x]])) - (emacsql db [:insert-into foo :values ([1] [2] [3])]) + (emacsql db [:insert :into foo :values ([1] [2] [3])]) (should (equal (emacsql db [:select * :from foo]) '((1) (2) (3)))))) diff --git a/emacsql.el b/emacsql.el index 548606715f..b674bfbc9e 100644 --- a/emacsql.el +++ b/emacsql.el @@ -36,7 +36,7 @@ ;; Insert values into a table with `emacsql-insert'. -;; (emacsql db [:insert-into people +;; (emacsql db [:insert :into people ;; :values (["Jeff" 1000 60000.0] ["Susan" 1001 64000.0])]) ;; Currently all actions are synchronous and Emacs will block until @@ -135,7 +135,7 @@ CONN-SPEC is a connection specification like the call to (emacsql-with-connection (db \"company.db\") (emacsql db [:create-table foo [x]]) - (emacsql db [:insert-into foo :values ([1] [2] [3])]) + (emacsql db [:insert :into foo :values ([1] [2] [3])]) (emacsql db [:select * :from foo]))" (declare (indent 1)) `(let ((,(car conn-spec) (emacsql-connect ,@(cdr conn-spec)))) @@ -499,9 +499,15 @@ definitions for return from a `emacsql-defexpander'." (emacsql-with-vars "FROM " (var table :identifier))) -(emacsql-defexpander :insert-into (table) - "Expands to the INSERT INTO keywords." - (emacsql-with-vars "INSERT INTO " +(emacsql-defexpander :replace () + (list "REPLACE")) + +(emacsql-defexpander :insert () + (list "INSERT")) + +(emacsql-defexpander :into (table) + "Expands to the INTO keywords." + (emacsql-with-vars "INTO " (cl-typecase table (symbol (var table :identifier)) (list (cl-destructuring-bind (name columns) table @@ -537,9 +543,6 @@ definitions for return from a `emacsql-defexpander'." (emacsql-defexpander :delete () (list "DELETE")) -(emacsql-defexpander :replace () - (list "REPLACE")) - (emacsql-defexpander :values (values) (emacsql-with-vars "VALUES " (combine (emacsql--vector values))))