Introduction
Introduction
qb is a fluent query builder for CFML. It is heavily inspired by Eloquent from Laravel.
Using qb, you can:
Quickly scaffold simple queries
Make complex, out-of-order queries possible
Abstract away differences between database engines
Requirements
Adobe ColdFusion 2016+
Lucee 5+
qb supports four major database grammars:
MySQL (
MySQLGrammar
)Oracle (
OracleGrammar
)Postgres (
PostgresGrammar
)Microsoft SQL Server (
SqlServerGrammar
)
Installation
Installation is easy through CommandBox and ForgeBox. Simply type box install qb
to get started.
Code Samples
Compare these two examples:
The differences become even more stark when we introduce more complexity:
With qb you can easily handle setting order by statements before the columns you want or join statements after a where clause:
qb enables you to explore new ways of organizing your code by letting you pass around a query builder object that will compile down to the right SQL without you having to keep track of the order, whitespace, or other SQL gotchas!
Here's a gist with an example of the powerful models you can create with this! https://gist.github.com/elpete/80d641b98025f16059f6476561d88202
Usage
To start a new query, instantiate a new Builder: wirebox.getInstance('QueryBuilder@qb')
.
By default, qb uses a generic Grammar. You can specify your specific grammar in ColdBox by setting the defaultGrammar
in your moduleSettings
.
If you are not using WireBox, just make sure to wire up the Builder
object with the correct grammar:
Last updated