Query parsing functions for Clojure on NodeJS
Initially intended for Macchiato as a port of PREQL. We'll likely expand it into its own as we go.
This namespace only builds the queries as functions. Database access is expected to take place elsewhere, likely in an abstracted manner. For an example, see macchiato-db-scratchpad
Approach and limitations
- One query, one file.
- Queries functions are named after the file that stores them.
- Positional arguments only, doesn't yet take a HugSQL-like parameter map.
Assume any functions are currently a work-in-progress and may change before we hit 0.1.0.
This project uses Github Flow. Please make pull requests agains master, working off a feature or fix branch.
Feedback welcome. You can find us on:
make-query-map to generate query functions from a folder.
(def queries (sql/make-query-map (sql/load-queries "your/sql-files")))
This will return a map where the query functions are indexed by the query's file name.
(def db-insert (:insert-name queryies))
Each function will expect as its first parameter a first-order function that will actually execute the query, and then a list of values to pass.
For example, from macchiato-db-scratchpad:
(defn add-new-users  (db/with-transaction (fn [conn] (db-insert conn "joeBob" 21) (db-insert conn "jack" 25) (db-insert conn "Unnamed" nil) true)))
The project contains tests for query parsing and loading. See macchiato-db-scratchpad for examples of how to use them against a PostgreSQL database.
macchiato.test.sql contains more examples as test functions.
Distributed under the MIT License