emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/emacsql 208885e264 031/427: Add testing to schema handling


From: ELPA Syncer
Subject: [nongnu] elpa/emacsql 208885e264 031/427: Add testing to schema handling.
Date: Tue, 13 Dec 2022 02:59:25 -0500 (EST)

branch: elpa/emacsql
commit 208885e264df0abdaa55ff7d2a5214c554fc694f
Author: Christopher Wellons <wellons@nullprogram.com>
Commit: Christopher Wellons <wellons@nullprogram.com>

    Add testing to schema handling.
---
 emacsql-tests.el | 11 +++++++++++
 emacsql.el       |  4 +++-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/emacsql-tests.el b/emacsql-tests.el
index 548eb807b6..481c09c566 100644
--- a/emacsql-tests.el
+++ b/emacsql-tests.el
@@ -16,3 +16,14 @@
   (should (string= (emacsql-escape-value [1 2 3]) "'[1 2 3]'"))
   (should (string= (emacsql-escape-value '(a b c)) "'(a b c)'"))
   (should (string= (emacsql-escape-value nil) "NULL")))
+
+(ert-deftest emacsql-schema ()
+  (should (string= (emacsql--schema-to-string [a]) "a"))
+  (should (string= (emacsql--schema-to-string [a b c]) "a, b, c"))
+  (should (string= (emacsql--schema-to-string [a (b)]) "a, b"))
+  (should (string= (emacsql--schema-to-string [a (b float)])
+                   "a, b REAL"))
+  (should (string= (emacsql--schema-to-string [a (b :primary float :unique)])
+                   "a, b REAL PRIMARY KEY UNIQUE"))
+  (should (string= (emacsql--schema-to-string [(a integer) (b float)])
+                   "a INTEGER, b REAL")))
diff --git a/emacsql.el b/emacsql.el
index fd043d7f2f..fa75f38ef5 100644
--- a/emacsql.el
+++ b/emacsql.el
@@ -250,10 +250,12 @@ If NAMED is non-nil, don't include column names."
 
 (defun emacsql-create (conn table schema &optional if-not-exists)
   "Create TABLE in CONN with SCHEMA."
+  (when (= 0 (length schema))
+    (error "Schema must not be empty."))
   (emacsql-with-errors conn
     (emacsql--send
      conn
-     (format "CREATE TABLE %s%s(%s);"
+     (format "CREATE TABLE %s%s (%s);"
              (if if-not-exists "IF NOT EXISTS " "")
              (emacsql-escape table)
              (emacsql--schema-to-string schema)))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]