chickadee » awful » $db

$db q #!key (default '()) valuesprocedure

Execute the given query (q) on the database and return the result as a list of lists or default if the result set is empty.

The values keyword parameter (a list) is a list of values to replace the placeholders in the query.

Example:

($db "insert into foo (bar, baz) values (?, ?)" values: '("bar-val" "baz-val"))

Note: up to version 0.40.0, $db returned #f when queries returned empty set of results. Starting from version 0.41.0, $db returns '() queries return empty set of results.

If you use the awful-ssql egg, you can give $db the query as a SSQL expression. See the documentation for awful-ssql for more details. Support for SSQL has been introduced in awful version 0.40.0.

Note that $db is supposed to be used in the context of request handlers (i.e., in the body of a lambda bound to a uri path by define-page).

If you want to use $db out of the context of request handlers, you'll have to manage database connections yourself. Basically, you have to parameterize db-connection with the actual connection object. Example:

(parameterize ((db-connection (open-database (db-credentials))))
  ($db the-query)
  (close-database (db-connection)))