|
18 | 18 | ;; databases. On MELPA, each of the backends is provided through |
19 | 19 | ;; separate packages: emacsql-sqlite, emacsql-psql, emacsql-mysql. |
20 | 20 |
|
21 | | -;; Most EmacSQL functions operate on a database connection. For |
22 | | -;; example, a connection to SQLite is established with |
23 | | -;; `emacsql-sqlite'. For each such connection a sqlite3 inferior |
24 | | -;; process is kept alive in the background. Connections are closed |
25 | | -;; with `emacsql-close'. |
26 | | - |
27 | | -;; (defvar db (emacsql-sqlite "company.db")) |
28 | | - |
29 | | -;; Use `emacsql' to send an s-expression SQL statements to a connected |
30 | | -;; database. Identifiers for tables and columns are symbols. SQL |
31 | | -;; keywords are lisp keywords. Anything else is data. |
32 | | - |
33 | | -;; (emacsql db [:create-table people ([name id salary])]) |
34 | | - |
35 | | -;; Column constraints can optionally be provided in the schema. |
36 | | - |
37 | | -;; (emacsql db [:create-table people ([name (id integer :unique) salary])]) |
38 | | - |
39 | | -;; Insert some values. |
40 | | - |
41 | | -;; (emacsql db [:insert :into people |
42 | | -;; :values (["Jeff" 1000 60000.0] ["Susan" 1001 64000.0])]) |
43 | | - |
44 | | -;; Currently all actions are synchronous and Emacs will block until |
45 | | -;; SQLite has indicated it is finished processing the last command. |
46 | | - |
47 | | -;; Query the database for results: |
48 | | - |
49 | | -;; (emacsql db [:select [name id] :from employees :where (> salary 60000)]) |
50 | | -;; ;; => (("Susan" 1001)) |
51 | | - |
52 | | -;; Queries can be templates -- $i1, $s2, etc. -- so they don't need to |
53 | | -;; be built up dynamically: |
54 | | - |
55 | | -;; (emacsql db |
56 | | -;; [:select [name id] :from employees :where (> salary $s1)] |
57 | | -;; 50000) |
58 | | -;; ;; => (("Jeff" 1000) ("Susan" 1001)) |
59 | | - |
60 | | -;; The letter declares the type (identifier, scalar, vector, Schema) |
61 | | -;; and the number declares the argument position. |
62 | | - |
63 | 21 | ;; See README.md for much more complete documentation. |
64 | 22 |
|
65 | 23 | ;;; Code: |
|
0 commit comments