brettatoms / zodiac-sql

A Zodiac extension for connecting to a SQL database

Home Page:https://cljdoc.org/d/com.github.brettatoms/zodiac-sql

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Zodiac SQL

Clojars Project

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.

Getting started

(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})

Options

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.

About

A Zodiac extension for connecting to a SQL database

https://cljdoc.org/d/com.github.brettatoms/zodiac-sql

License:MIT License


Languages

Language:Clojure 100.0%