branch: elpa/emacsql commit 7e18a43da17bf0df75f6ec077250b87671f7e797 Author: Christopher Wellons <well...@nullprogram.com> Commit: Christopher Wellons <well...@nullprogram.com>
Add a template example. --- README.md | 8 +++++++- emacsql.el | 17 +++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index f323cf7f88..cac2ff25a4 100644 --- a/README.md +++ b/README.md @@ -29,8 +29,14 @@ Requires Emacs 24 or later. ["Susan" 1001 64000.0]) ;; Query the database for results: -(emacsql db [:select [name id] :from employees :where (> salary 60000)]) +(emacsql db [:select [name id] :from employees :where (> salary 62000)]) ;; => (("Susan" 1001)) + +;; Queries can be templates using $1, $2, etc.: +(emacsql db + [:select [name id] :from employees :where (> salary $1)] + 50000) +;; => (("Jeff" 1000) ("Susan" 1001)) ``` ## Limitations diff --git a/emacsql.el b/emacsql.el index ef6a7a0188..ae596c15bd 100644 --- a/emacsql.el +++ b/emacsql.el @@ -26,26 +26,31 @@ ;; Table identifiers can be any lisp object: string, symbol, etc. I ;; suggest using a symbol. Use `emacsql-create' to create a table. -;; (emacsql-create db :employees [name id salary]) +;; (emacsql-create db 'employees [name id salary]) ;; Column constraints can optionally be provided. -;; (emacsql-create db :employees [(name text) (id integer) (salary real)]) +;; (emacsql-create db 'employees [name (id integer) (salary real)]) ;; Insert values into a table with `emacsql-insert'. -;; (emacsql-insert db :employees ["Jeff" 1000 60000.0] +;; (emacsql-insert db 'employees ["Jeff" 1000 60000.0] ;; ["Susan" 1001 64000.0]) ;; Currently all actions are synchronous and Emacs will block until ;; SQLite has indicated it is finished processing the last command. -;; High-level query construction is still a work-in-progress: +;; Query the database for results: -;; (emacsql-select-raw db (concat "SELECT name, id FROM ':employees' " -;; "WHERE salary > 60000;")) +;; (emacsql db [:select [name id] :from employees :where (> salary 60000)]) ;; ;; => (("Susan" 1001)) +;; Queries can be templates using $1, $2, etc.: +;; (emacsql db +;; [:select [name id] :from employees :where (> salary $1)] +;; 50000) +;; ;; => (("Jeff" 1000) ("Susan" 1001)) + ;; Limitations: ;; Due to limitations of the SQLite command line program, emacsql is