branch: elpa/emacsql commit 208885e264df0abdaa55ff7d2a5214c554fc694f Author: Christopher Wellons <well...@nullprogram.com> Commit: Christopher Wellons <well...@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)))))