Emitter is part of floor-plan that tells Walkable how to generate SQL strings in respect of your database.

Emitter is a hash-map with the following keys :quote-marks, :transform-table-name, :transform-column-name, :rename-tables, :rename-columns, :rename-keywords, :wrap-select-strings.

Pre-defined emitters

There are some pre-defined emitters in walkable.sql-query-builder.emitter namespace, namely sqlite-emitter, mysql-emitter and postgres-emitter. You may make your own emitter from scratch (which means providing all the above keywords), but it's better to start from one of the pre-defined emitters and override your custom keys:

(def your-emitter (merge emitter/postgres-emitter {...your customizations...}))

: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 example, 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):

Emitter
Keyword
Real table in database
(def your-emitter
  (merge emitter/postgres-emitter
    {: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:

Emitter
Keyword
Real table in database
(def your-emitter
  (merge emitter/postgres-emitter
    {: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.

Emitter
Keywords
Real table+column in database
(def your-emitter
  (merge emitter/postgres-emitter
    {: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)

results matching ""

    No results matching ""