An extension for Zodiac to help with connecting to a SQL database with next.jdbc and execute queries with HoneySQL.
For an example of how to use this extension see examples/hello-world.
(ns myapp
(:require [zodiac.core :as z]
[zodiac.ext.sql :as z.sql]))
(defn handler [{:keys [::z/context]}]
(let [{:keys [db]} context
{:keys [message]} (z.sql/execute-one! db {:select [["hello world" :message]]})]
[:html
[:head
[:meta {:name "viewport"
:content "width=device-width, initial-scale=1"}]]
[:body
message]]))
(defn routes []
["/" {:get #'handler}])
(let [sql-ext (z.sql/init {:spec {:jdbcUrl "jdbc:sqlite:hello-world.db"}})]
(z/start {:extensions [sql-ext]
:routes #'routes})
The zodiac.ext.sql/init
accepts the following options:
:spec
: The datasource and connection options map. For more information see Datasources and Connections in the next.jdbc docs:jdbc-options
: The options for building generating SQL and results set. For more information see Generating SQL and Generating Rows and Result Sets in the next.jdbc docs.:context-key
: The key in the zodiac request context that will hold the database connection. Defaults to :db
.Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close