Pure functions for SQL query building and transformation.
All functions in this namespace are pure - they take data and return data without side effects. No I/O, logging, or state mutation.
Pure functions for SQL query building and transformation. All functions in this namespace are pure - they take data and return data without side effects. No I/O, logging, or state mutation.
(adapter-dialect->honey-dialect adapter-dialect)Map adapter dialect keyword to HoneySQL-supported dialect.
Pure function: deterministic mapping with no side effects.
Args: adapter-dialect: Keyword dialect from adapter (:sqlite, :postgresql, etc.)
Returns: HoneySQL dialect keyword or nil for ANSI SQL
Example: (adapter-dialect->honey-dialect :sqlite) => nil (adapter-dialect->honey-dialect :postgresql) => :postgresql
Map adapter dialect keyword to HoneySQL-supported dialect. Pure function: deterministic mapping with no side effects. Args: adapter-dialect: Keyword dialect from adapter (:sqlite, :postgresql, etc.) Returns: HoneySQL dialect keyword or nil for ANSI SQL Example: (adapter-dialect->honey-dialect :sqlite) => nil (adapter-dialect->honey-dialect :postgresql) => :postgresql
(build-ordering options default-field)Build ORDER BY clause from sort options.
Pure function: constructs ordering specification.
Args: options: Map with optional :sort-by and :sort-direction keys default-field: Default field keyword to sort by
Returns: Vector of [field direction] pairs for HoneySQL
Example: (build-ordering {:sort-by :created-at :sort-direction :desc} :id) => [[:created-at :desc]]
Build ORDER BY clause from sort options.
Pure function: constructs ordering specification.
Args:
options: Map with optional :sort-by and :sort-direction keys
default-field: Default field keyword to sort by
Returns:
Vector of [field direction] pairs for HoneySQL
Example:
(build-ordering {:sort-by :created-at :sort-direction :desc} :id)
=> [[:created-at :desc]](build-pagination options)Build LIMIT/OFFSET clause with safe bounds checking.
Pure function: validates and constrains pagination parameters.
Args: options: Map with optional :limit and :offset keys
Returns: Map with sanitized :limit and :offset values
Example: (build-pagination {:limit 50 :offset 100}) => {:limit 50 :offset 100}
(build-pagination {:limit 5000}) => {:limit 1000 :offset 0} ; Clamped to max
Build LIMIT/OFFSET clause with safe bounds checking.
Pure function: validates and constrains pagination parameters.
Args:
options: Map with optional :limit and :offset keys
Returns:
Map with sanitized :limit and :offset values
Example:
(build-pagination {:limit 50 :offset 100})
=> {:limit 50 :offset 100}
(build-pagination {:limit 5000})
=> {:limit 1000 :offset 0} ; Clamped to max(build-where-filters filters)Build WHERE clause conditions from filter map with proper type conversions.
Pure function: transforms filter map to HoneySQL conditions with type handling. Converts kebab-case field names to snake_case for database compatibility.
Args: filters: Map of kebab-case field keywords -> value filters
Returns: HoneySQL WHERE clause vector with snake_case field names or nil if no filters
Type Handling:
Field Name Handling:
Example: (build-where-filters {:name "John" :active true}) => [:and [:= :name "John"] [:= :active true]]
(build-where-filters {:role [:admin :user]}) => [:and [:in :role ["admin" "user"]]]
(build-where-filters {:tenant-id #uuid "..." :deleted-at nil}) => [:and [:= :tenant_id "..."] [:is :deleted_at nil]]
Build WHERE clause conditions from filter map with proper type conversions.
Pure function: transforms filter map to HoneySQL conditions with type handling.
Converts kebab-case field names to snake_case for database compatibility.
Args:
filters: Map of kebab-case field keywords -> value filters
Returns:
HoneySQL WHERE clause vector with snake_case field names or nil if no filters
Type Handling:
- UUID: converted to string for DB storage
- Keyword values: converted to string for DB storage
- Boolean: passed as-is (adapter handles DB-specific conversion)
- Sequential values: used with IN clause, items converted if needed
- nil: used with IS NULL clause
Field Name Handling:
- Kebab-case keywords (e.g., :tenant-id) converted to snake_case (e.g., :tenant_id)
Example:
(build-where-filters {:name "John" :active true})
=> [:and [:= :name "John"] [:= :active true]]
(build-where-filters {:role [:admin :user]})
=> [:and [:in :role ["admin" "user"]]]
(build-where-filters {:tenant-id #uuid "..." :deleted-at nil})
=> [:and [:= :tenant_id "..."] [:is :deleted_at nil]]Default number of results to return when no limit is specified.
Default number of results to return when no limit is specified.
(format-sql adapter-dialect query-map)Format HoneySQL query map to SQL string with parameters. Converts kebab-case identifiers to snake_case at database boundary.
Pure function: transforms data structure to SQL without executing it.
Args: adapter-dialect: Database dialect keyword query-map: HoneySQL query map (with kebab-case identifiers)
Returns: Vector of [sql-string & parameters]
Example: (format-sql :postgresql {:select [:*] :from [:users]}) => ["SELECT * FROM users"]
(format-sql :postgresql {:select [:*] :from [:user-profiles]}) => ["SELECT * FROM user_profiles"]
Format HoneySQL query map to SQL string with parameters.
Converts kebab-case identifiers to snake_case at database boundary.
Pure function: transforms data structure to SQL without executing it.
Args:
adapter-dialect: Database dialect keyword
query-map: HoneySQL query map (with kebab-case identifiers)
Returns:
Vector of [sql-string & parameters]
Example:
(format-sql :postgresql {:select [:*] :from [:users]})
=> ["SELECT * FROM users"]
(format-sql :postgresql {:select [:*] :from [:user-profiles]})
=> ["SELECT * FROM user_profiles"](format-sql-with-opts adapter-dialect query-map opts)Format HoneySQL query map with custom options. Converts kebab-case identifiers to snake_case at database boundary.
Pure function: transforms data with configuration.
Args: adapter-dialect: Database dialect keyword query-map: HoneySQL query map (with kebab-case identifiers) opts: Additional HoneySQL formatting options
Returns: Vector of [sql-string & parameters]
Format HoneySQL query map with custom options. Converts kebab-case identifiers to snake_case at database boundary. Pure function: transforms data with configuration. Args: adapter-dialect: Database dialect keyword query-map: HoneySQL query map (with kebab-case identifiers) opts: Additional HoneySQL formatting options Returns: Vector of [sql-string & parameters]
Maximum allowed pagination limit to prevent excessive memory usage.
Maximum allowed pagination limit to prevent excessive memory usage.
Minimum allowed pagination limit.
Minimum allowed pagination limit.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |