A library for simple PostgreSQL queries with namespaced keys.
specql introspects your database at compile time and generates clojure.spec definitions for the rows and all the columns. You can then query for rows by giving a table, the keys to return and a map of keys to match against.
For a quick intro, see my talk about specql at ClojuTRE 2017 Scrap your query boilerplate with specql
See the docs for more examples.
(def db (make-my-db))
;; Define tables as [table-name :namespaced/table-keyword]
;; specql automatically creates specs for the columns of the table (in the same namespace as the
;; table keyword). For example if :employee/employees is the table and it has "id" and "name"
;; columns, specql will generate :employee/id and :employee/name specs with predicates
;; determined by the column data type
(define-tables define-db
["address" :address/address]
["employee" :employee/employees]
["department" :department/departments])
;; Querying
(fetch db
;; The table to query from
:employee/employees
;; the columns to return
#{:employee/id :employee/name :employee/title :employee/address}
;; the where clause
{:employee/id 1})
;; => ({:employee/id 1
;; :employee/name "Wile E. Coyote"
;; :employee/title "Super genius"
;; :employee/address {:address/street "Desert avenue 1"
;; :address/postal-code "31173"
;; :address/country "US"}})
specql.postgis
namespace that adds composite parsing support for geometry (requires postgis Java classes)Birthday release! Specql is now 1 year old.
refresh!
to refresh a materialized viewupdate!
with empty where clausenil
value when in a to-keyword
transformed compositeORDER BY
column with table aliasCHAR(n)
type) in composite parsingclojure.future
requires as 1.9 is nearing release:specql.core/transform-column-name
option to define-tablesALTER TYPE
)specql/transform
definitions to composite array elements when readingROW(?,...)::typename
inserts with complex compositescolumns
and tables
for querying the runtime registryThis is very much still work in progress.
Features I intend to implement:
This library is NOT intended to replace having to write SQL. The more complex SQL (like reporting queries and complex joins) queries are better written as SQL. Use yesql/jeesql/hugsql or the like.
This library intends to provide the most common case of CRUD queries and defer to SQL on the more difficult ones.
Specql can use VIEWs in the database just like tables, so you can write your complex queries as views and use them via specql.
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close