branch: elpa/emacsql commit 97e9764343bebab0088c9c7c99fd53ac2b2f5615 Author: Christopher Wellons <well...@nullprogram.com> Commit: Christopher Wellons <well...@nullprogram.com>
Change the API of emacsql-insert. --- README.md | 4 ++-- emacsql.el | 21 +++++++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 0db964a4b2..eae6f6aea2 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,8 @@ requests are synchronous. (emacsql-create db :employees '((name text) (id integer) salary)) ;; Insert some data: -(emacsql-insert db :employees "Jeff" 1000 60000) -(emacsql-insert db :employees "Susan" 1001 64000) +(emacsql-insert db :employees ["Jeff" 1000 60000] + ["Susan" 1001 64000]) ;; The high-level SELECT interface is a work in progress. (emacsql-select-raw db (concat "SELECT name, id FROM ':employees' " diff --git a/emacsql.el b/emacsql.el index 8c3d91c9ef..ed81295794 100644 --- a/emacsql.el +++ b/emacsql.el @@ -29,8 +29,8 @@ ;; Insert values into a table with `emacsql-insert'. -;; (emacsql-insert db :employees "Jeff" 1000 60000) -;; (emacsql-insert db :employees "Susan" 1001 64000) +;; (emacsql-insert db :employees ["Jeff" 1000 60000] +;; ["Susan" 1001 64000]) ;; Currently all actions are synchronous and Emacs will block until ;; SQLite has indicated it is finished processing the last command. @@ -230,13 +230,18 @@ buffer. This is for debugging purposes." (prin1-to-string value) (emacsql-escape (prin1-to-string value))))) -(defun emacsql-insert (emacsql table &rest values) - "Insert VALUES into TABLE." +(defun emacsql-insert (emacsql table &rest rows) + "Insert ROWS into TABLE. +Each row must be a sequence of values to store into TABLE. + + (emacsql-insert db :table '(\"Chris\" 0) [\"Jeff\" 1])" (emacsql-with-errors emacsql - (emacsql--send emacsql - (format "INSERT INTO %s VALUES(%s);" - (emacsql-escape table) - (mapconcat #'emacsql-escape-value values ", "))))) + (emacsql--send + emacsql + (format "INSERT INTO %s VALUES (%s);" (emacsql-escape table) + (mapconcat (lambda (row) + (mapconcat #'emacsql-escape-value row ", ")) + rows "), ("))))) (defun emacsql-select-raw (emacsql query) "Send a raw QUERY string to EMACSQL."