the query string, same syntax as search
the database whose schema decides how each field is compared
options to customize the parsing
The WHERE condition and the values to bind
const { where, values } = buildWhere('name:~ester mw:100..500', db, {
tableName: 'molecules',
});
const sql = `SELECT id FROM molecules WHERE ${where || '1 = 1'} ORDER BY mw LIMIT :limit OFFSET :offset`;
const rows = db.prepare(sql).all({ ...values, limit: 50, offset: 0 });
const { total } = db
.prepare(`SELECT COUNT(*) AS total FROM molecules WHERE ${where || '1 = 1'}`)
.get(values);
Translate a query string into a WHERE condition plus its bound parameters, without running it. This is the composable half of search: the caller owns the statement and can add its own joins,
ORDER BY,LIMIT/OFFSET, or wrap it in aCOUNT(*)— none of whichsearchcan express.The emitted parameters are named (
:column_i_j), so they can be merged with the caller's own named parameters without colliding on position.