Engines and Binding

A gesundheit query must be “bound” to an “engine” to render and/or execute. For apps that deal with a single database, you can simply create an engine instance during application startup, assign it to gesundheit.defaultEngine and not have to think about binding after that.

Engine API Reference

class Engine

Engine is gesundheits interface to an actual database.

Engines have all of the query factory functions attached to them as instance methods that automatically bind created queries to the engine. They also have these additionaly methods

static method Engine.create(dbUrl, poolOptions)

Create an Engine instance from an Any-DB connect string and extra connection pool options, this is exported by gesundheit as gesundheit.engine(...).

This example shows the most common way to set up a single default database engine for an application.

method Engine.query(statement, params, callback)

Passes arguments directly to the query method of the underlying Any-DB ConnectionPool

method Engine.begin(callback)

Start a new transaction and return it.

The returned object behaves exactly like a new engine, but has commit and rollback methods instead of close. (In fact it’s an Any-DB Transaction that has had the query factory functions mixed in to it).

method Engine.compile(root)

Render an AST to a SQL string and collect parameters

method Engine.close()

Closes the internal connection pool.

function fakePool()

Create a fake database connection pool that throws errors if you try to execute a query.