[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/emacsql e859204451 064/427: Flesh out more README.
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/emacsql e859204451 064/427: Flesh out more README. |
Date: |
Tue, 13 Dec 2022 02:59:28 -0500 (EST) |
branch: elpa/emacsql
commit e8592044516ef4d36f5a66f4957f67f58f2d35f1
Author: Christopher Wellons <wellons@nullprogram.com>
Commit: Christopher Wellons <wellons@nullprogram.com>
Flesh out more README.
---
README.md | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 75 insertions(+), 3 deletions(-)
diff --git a/README.md b/README.md
index cac2ff25a4..9c4f4f610d 100644
--- a/README.md
+++ b/README.md
@@ -8,13 +8,15 @@ It works by keeping a `sqlite3` inferior process running (a
are automatically cleaned up if they are garbage collected. All
requests are synchronous.
-Any [readable lisp value][readable] can be stored as values in
+Any [readable lisp value][readable] can be stored as a value in
Emacsql, including numbers, strings, symbols, lists, vectors, and
-closures. Emacsql has no concept of "TEXT" values, it's all just lisp
+closures. Emacsql has no concept of "TEXT" values; it's all just lisp
objects.
Requires Emacs 24 or later.
+## Usage
+
```el
(defvar db (emacsql-connect "company.db"))
@@ -32,13 +34,83 @@ Requires Emacs 24 or later.
(emacsql db [:select [name id] :from employees :where (> salary 62000)])
;; => (("Susan" 1001))
-;; Queries can be templates using $1, $2, etc.:
+;; Queries can be templates, using $1, $2, etc.:
(emacsql db
[:select [name id] :from employees :where (> salary $1)]
50000)
;; => (("Jeff" 1000) ("Susan" 1001))
```
+## Operators
+
+Emacsql currently supports the following expression operators, named
+exactly like so in a structured Emacsql statement.
+
+ * / % + - << >> &
+ | < <= > >= = !=
+ is like glob and or
+
+The `<=` and `>=` operators accept 2 or 3 operands, transforming into
+a SQL `_ BETWEEN _ AND _` operator as appropriate.
+
+With `glob` and `like` keep in mind that they're matching the
+*printed* representations of these values, even if the value is a
+string.
+
+The `||` concatenation operator is unsupported because concatenating
+printed represenations breaks an important constraint: all values must
+remain readable within SQLite.
+
+## Structured Statements
+
+The database is interacted with via structured s-expression
+statements. You won't be concatenating strings on your own. (And it
+leaves out any possibility of a SQL injection!) See the "Usage"
+section above for examples. A statement is a vector of keywords and
+other lisp object.
+
+Structured Emacsql statements are compiled into SQL statements. The
+statement compiler is memoized so that using the same statement
+multiple times is fast. To assist in this, the statement can act as a
+template -- using `$1`, `$2`, etc. -- working like the Elisp `format`
+function.
+
+### Keywords
+
+Rather than the typical uppercase SQL keywords, keywords in a
+structured Emacsql statement are literally just that: lisp keywords.
+When multiple keywords appear in sequence, Emacsql will generally
+concatenate them with a dash, e.g. `CREATE TABLE` becomes
+`:create-table`.
+
+ * `:create-table <ident> <schema>`
+
+ ex. [:create-table employees [name (id integer :primary) (salary float)]]
+
+ * `:drop-table <ident>`
+
+ ex. [:drop-table employees]
+
+ * `:select <column-spec>`
+
+ ex. [:select [name (/ salary 52)] ...]
+
+`column-spec` can be a `*` symbol or a vector of column identifiers,
+optionally as expressions.
+
+ * `:from <ident>`
+
+ ex. [... :from employees]
+
+### Templates
+
+To make statement compilation faster, and to avoid making you build up
+statements dynamically, you can insert `$n` "variables" in place of
+identifiers and values. These refer to argument positions after the
+statement in the `emacsql` function, 1-indexed.
+
+ (emacsql db [:select * :from $1 :where (> salary $2)] 'employees 50000)
+
## Limitations
Emacsql is *not* intended to play well with other programs accessing
- [nongnu] elpa/emacsql 896bb7ce52 035/427: Start adding SQL expanders., (continued)
- [nongnu] elpa/emacsql 896bb7ce52 035/427: Start adding SQL expanders., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 9272d13ace 036/427: Add some tests for the expanders., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 3511a0df1d 037/427: Add a top-level query function, emacsql., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 7e18a43da1 039/427: Add a template example., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 8b2cf8c208 041/427: Fix up :where., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql c92c56ce55 003/427: Add a close buffer sentinel., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 1a84c983cf 013/427: No named results by default., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 76a430032e 014/427: Fix up old test., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 36c6aae4b5 042/427: Drop raw select., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 77ae713186 046/427: Create table expander., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql e859204451 064/427: Flesh out more README.,
ELPA Syncer <=
- [nongnu] elpa/emacsql 35676bb560 065/427: Fix README examples., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 847f3bd87f 078/427: Add new keywords to listing., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql a9b9d6bfc8 083/427: Fix typo in README., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 29f65b3b8e 093/427: Update Windows statement in the README., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql b447994514 033/427: Change table type recommendation., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 4fa57ba758 051/427: Fully drop named parsing., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 7c572d688d 052/427: Fix % operator situation., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 84499878d0 081/427: Add :union, :union-all, :difference, and :except., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql a1ce9f16f2 097/427: Add emacsql-with-connection back in., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 7cfed08ab8 099/427: Add docstring to emacsql--log., ELPA Syncer, 2022/12/13