define-query
define-query-definer
define-id
8.15.0.2

define-query🔗ℹ

Bogdan Popa <bogdan@defn.io>

This module provides utilities for turning ".sql" files into virtual-statements in a way that cooperates with raco dist.

syntax

(define-query-definer define-id path-expr)

 
  path-expr : (or/c path? path-string?)
Binds define-id as a form that defines queries by referencing ".sql" files located at path-expr. The referenced files are automatically bundled together with an application during distribution (à la define-runtime-path).

The syntax of define-id is:

syntax

(define-id binder ...+)

 
binder = query-id
  | [query-id filename-expr]
 
  filename-expr : path-string?

A define-id form binds the query-ids by loading the contents of their associated files (relative to path-expr) at runtime and passing those contents to virtual-statement. If a filename-expr is not provided for a binder, it defaults to the result of appending ".sql" to the string version of query-id.

For example:

(define-query-definer define-metadata-query
  "metadata-queries")
(define-metadata-query
  get-metadata
  put-metadata)
(query-exec db-conn put-metadata "example" 42)
(query-value db-conn get-metadata "example")