NAME
db/rowquill/sqlbuilder - SQL builders for Rowquill.
SYNOPSIS
from db/rowquill/sqlbuilder import build_limit, build_order, build_where;
from std/db import DB;
let dbh := DB.connect("...");
let where := build_where( { name: [ "ILIKE", "%rob%" ] } );
let order := build_order( { order_by: [ [ "name", "ASC" ] ] } );
let limit := build_limit( { limit: 20, page: 2 } );
let binds := where{binds};
for ( let value in limit{binds} ) {
binds.push(value);
}
let sth := dbh.prepare(
`SELECT * FROM people WHERE ${where{sql}}${order}${limit{sql}}`
);
sth.execute( binds );
while ( let row := sth.next_typed_dict() ) {
...;
}
DESCRIPTION
build_where turns Rowquill search condition data structures into a SQL WHERE fragment plus bind values. build_order builds an ORDER BY fragment, and build_limit builds a LIMIT/OFFSET fragment plus bind values. build_limit also accepts page as an alternative to offset, calculating the offset as ( page - 1 ) * limit. Callers can supply callbacks for column quoting and value deflation.
COPYRIGHT AND LICENCE
db/rowquill/sqlbuilder is copyright Toby Inkster.
It is free software; you may redistribute it and/or modify it under the terms of either the Artistic License 1.0 or the GNU General Public License version 2.