branch: elpa/emacsql
commit ad3483c97c8197e1adc06ca5011185397b291ce0
Author: Jonas Bernoulli <jo...@bernoul.li>
Commit: Jonas Bernoulli <jo...@bernoul.li>

    emacsql-sqlite-list-tables: New function
---
 emacsql-sqlite-common.el | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/emacsql-sqlite-common.el b/emacsql-sqlite-common.el
index 15a879bebe..216dbcc47a 100644
--- a/emacsql-sqlite-common.el
+++ b/emacsql-sqlite-common.el
@@ -83,6 +83,22 @@ Also see http://www.sqlite.org/lang_keywords.html.";)
 Elements have the form (ERRCODE SYMBOLIC-NAME EMACSQL-ERROR
 ERRSTR).  Also see https://www.sqlite.org/rescode.html.";)
 
+;;; Utilities
+
+(defun emacsql-sqlite-list-tables (connection)
+  "Return a list of the names of all tables in CONNECTION.
+Tables whose names begin with \"sqlite_\", are not included
+in the returned value."
+  (emacsql connection
+           [:select name
+            ;; The new name is `sqlite-schema', but this name
+            ;; is supported by old and new SQLite versions.
+            ;; See https://www.sqlite.org/schematab.html.
+            :from sqlite-master
+            :where (and (= type 'table)
+                        (not-like name "sqlite_%"))
+            :order-by [(asc name)]]))
+
 (provide 'emacsql-sqlite-common)
 
 ;;; emacsql-sqlite-common.el ends here

Reply via email to