dbee is a library that provides a convenient API for executing HoneySQL queries.
To get started, you will need to include the following dependency in your project file. You will also need to provide a database adapter compatible with java.jdbc. Refer to the configuration docs for more information.
dbee requires Clojure 1.9 or later.
The following demonstrates calling dbee.core/defdb
to create a database API
in a namespace myproject.db
. The defdb
macro will create several functions
in the calling namespace that execute HoneySQL queries against the database.
It should be noted that the configuration map in defdb
is wrapped in a
delay
so you can load some of the configuration at runtime such as
credentials.
It should also be noted that you do not have to use defdb
to generate a local
database API. You can use the functions in dbee.core
directly if you prefer.
The functions provide a more java.jdbc-like interface. Refer to the
configuration docs for more information.
(ns myproject.db
(:refer-clojure :exclude [get update])
(:require [dbee.core :refer [defdb]]))
(defdb {:adapter "postgresql"
:database-name "mydb"
:server-name "localhost"
:username "postgres"
:password ""
:maximum-pool-size 10})
The following demonstrates using the API generated by defdb
at the REPL. Refer
to the query docs for more information on building queries.
The functions generated by defdb
have docstrings including examples.
> (require '[myproject.db :as db])
;; => nil
> (db/all {:from [:users] :select [:*]})
;; => ({:id 1 :name "John" :username "jdoe"} ...)
> (db/get :users 1)
;; => {:id 1 :name "John" :username "jdoe"}
Thanks to @hby for helping me work through some of the trickier macro bits.
The dbee API is inspired by Ecto.Repo. Thanks to the Ecto team for creating such a great library.
Copyright © 2019 Thomas C. Taylor and contributors.
Distributed under the Eclipse Public License version 2.0.
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close