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:

  • Postgres

  • Mysql

;; 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):

  • Registry

  • Keyword

  • Real table in database

[{: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:

  • Registry

  • Keyword

  • Real table in database

[{:key `walkable.sql-query-builder.floor-plan/emitter
  :base :postgres
  :rename-tables {"person" "people"}}]

:person/name, :person/age

people, as in this sql query:

SELECT "people"."name", "people"."age" FROM "people";

:rename-keywords

Maybe matching just the table name or the column name is not enough. You want to match the exact pair of table + column name.

  • Registry

  • Keywords

  • Real table & column in database

[{:key `walkable.sql-query-builder.floor-plan/emitter
  :base :postgres
  :rename-keywords {:person/type :person/typo}}]

:person/name, :person/type

"person"."typo", as in this sql query:

SELECT "person"."name", "person"."typo" FROM "person";

:wrap-select-strings

Specific to Sqlite. It’s unlikely that you want to override this. (Doc comming soon)