Liking cljdoc? Tell your friends :D

Getting Started

Let's get started by adding HoneyEQL to your project.

Clojars Project

In addition, you will need to add dependencies for the JDBC drivers you wish to use for whatever databases you are using and preferably a connection pooling library like HikariCP or c3p0.

This documentation uses deps and assumes you are connecting to the the sakila database created from this JOOQ's example repository.

;; deps.edn
{:paths ["src"]
 :deps  {com.github.tamizhvendan/honeyeql     {:mvn/version "1.0.0"}
         hikari-cp                   {:mvn/version "2.10.0"}
         org.postgresql/postgresql   {:mvn/version "42.2.8"}
         mysql/mysql-connector-java  {:mvn/version "8.0.19"}}}

The next step is initializing the db-adapter using either a db-spec-map or a DataSource.

Postgres with db-spec map

(ns core
  (:require [honeyeql.db :as heql-db]))

(def db-adapter (heql-db/initialize {:dbtype   "postgres"
                                     :dbname   "sakila"
                                     :user     "postgres"
                                     :password "postgres"}))

MySQL with a data source (via connection pool)

(ns core
  (:require [honeyeql.db :as heql-db]
            [hikari-cp.core :as hikari]))

(def db-adapter
  (heql-db/initialize
    (hikari/make-datasource
      {:server-name       "localhost"
       :maximum-pool-size 1
       :jdbc-url          "jdbc:mysql://localhost:3306/sakila"
       :driver-class-name "com.mysql.cj.jdbc.MysqlDataSource"
       :username          "root"
       :password          "mysql123"})))

Then we query the database using either query-single to retrieve a single item or query to retrieve multiple items.

(ns core
  (:require ; ...
            [honeyeql.core :as heql]))
; ...
; select first_name, last_name 
; from actor 
; where actor_id = 1
(heql/query-single
  db-adapter
  {[:actor/actor-id 1] [:actor/first-name
                        :actor/last-name]})
; returns
{:actor/first-name "PENELOPE"
 :actor/last-name  "GUINESS"}
; select name
; from language
(heql/query
  db-adapter
  {[] [:language/name]})

; returns
({:language/name "English"} {:language/name "Italian"}
 {:language/name "Japanese"} {:language/name "Mandarin"}
 {:language/name "French"} {:language/name "German"})

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close