Index: code-docs/sqlite-tools.scrbl ================================================================== --- code-docs/sqlite-tools.scrbl +++ code-docs/sqlite-tools.scrbl @@ -37,11 +37,12 @@ @defparam[sqltools:dbc con connection? #:value "No DB connection!"] The current database connection. This module assumes a single active connection and stores it in this parameter so you don’t have to pass it to a function every time you execute a query. It’s -provided here so you can use it directly with the functions provided by @racketmodname[db]. +provided here so you can use it directly with the functions provided by @racketmodname[db] (all of +which are re-provided by this module for convenience). @defboolparam[sqltools:log-queries? v #:value #f] A kill-switch that determines whether @racket[log-query] does anything. Index: sqlite-tools.rkt ================================================================== --- sqlite-tools.rkt +++ sqlite-tools.rkt @@ -59,12 +59,12 @@ [make-insert/replace-query (stringish? (listof stringish?) . -> . string?)] [make-insert-rows-query (stringish? (listof stringish?) (listof (listof stringish?)) . -> . string?)] [make-select-query (stringish? (listof stringish?) #:where stringish? . -> . string?)] ;; Database operations - [init-db! ((pathish?) #:rest (listof string?) . ->* . void?)] - [query! ((string?) #:rest (listof any/c) . ->* . void?)] + [init-db! ((pathish?) () #:rest (listof string?) . ->* . void?)] + [query! ((string?) () #:rest (listof any/c) . ->* . void?)] [select-rows! (case-> (stringish? (listof stringish?) any/c . -> . (or/c empty? hash?)) (string? (listof stringish?) . -> . (or/c empty? hash?)))])) ;; ~~~ Private use ~~~ @@ -222,11 +222,12 @@ ;; Run a query with logging (if enabled) and return the result (define (query! q . parameters) (unless (good-connection?) (error "(query!) DB not connected")) (log-query q) - (apply query-exec (sqltools:dbc) q parameters)) + (cond [(empty? parameters) (query-exec (sqltools:dbc) q)] + [else (apply query-exec (sqltools:dbc) q parameters)])) ;; Run a SELECT query, return a hash with field names as keys (define select-rows! (case-lambda ;; Use arbitrary query @@ -249,11 +250,11 @@ (define TESTDB "SQLITE-TOOLS-TEST.sqlite") ;; Check that things start out uninitialized and that queries don’t work (check-equal? (sqltools:dbc) uninitialized-connection) (check-false (file-exists? TESTDB)) - (check-exn exn:fail? (lambda () (query! "-- nothing"))) + (check-exn exn:fail? (lambda () (query! "SELECT 1"))) (check-exn exn:fail? (lambda () (select-rows! 'posts '(title) 1))) ;; Initialize db connection, create file with no schema (test-begin (check-equal? (init-db! TESTDB) (void))