Emitter
Emitter is a set of information that tells Walkable how to generate SQL strings in respect of your database.
Pre-defined emitters
There are some pre-defined emitters in
walkable.sql-query-builder.emitter
namespace, namely
sqlite-emitter
, mysql-emitter
and postgres-emitter
.
Customize
You start with one of the pre-defined emitters and override your custom keys:
;; the registry
[{:key `walkable.sql-query-builder.floor-plan/emitter
:base :postgres
...your customizations...}]
Parts that you can change
:quote-marks
Different SQL databases use different strings to denote quotation.
For instance, MySQL use a pair of backticks:
SELECT * FROM `table`
while PostgreSQL use quotation marks:
SELECT * FROM "table"
You need to provide the :quote-marks
as a vector of two strings. For
example:
;; emitter for postgres
{:quote-marks ["\"", "\""]}
;; emitter for mysql
{:quote-marks ["`", "`"]}
It’s unlikely that you want to override :quote-marks
. Keep the one from pre-defined emitters.
:transform-table-name and :transform-column-name
By default the pre-defined emitters will replace dashes (-
) with
underscores (_
) in table names and column names. For instance, the
column :human-being/full-name
will be understood as column
full_name
in table human_being
. You can override that behavior
by providing your own function(s).
For example if all your real table names are upper-cased (while we all like our keywords being lower-cased):
[{:key `walkable.sql-query-builder.floor-plan/emitter
:base :postgres
:transform-table-name (fn [table-name] (clojure.string/upper-case table-name))}
...]
:person/name, :person/age
PERSON, as in this sql query:
SELECT "PERSON"."name", "PERSON"."age" FROM "PERSON";
:rename-tables, :rename-columns
Sometimes you want to specify the exact name, regardless of
:transform-table-name
/ :transform-column-name
functions: