qb

All Contributors Build Status

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 11+
  • Lucee 4.5+

Installation

Installation is easy through CommandBox and ForgeBox. Simply type box install qb to get started.

Code Samples

Compare these two examples:

// Plain old CFML
q = queryExecute("SELECT * FROM users");

// qb
query = wirebox.getInstance('QueryBuilder@qb');
q = query.from('users').get();

The differences become even more stark when we introduce more complexity:

// Plain old CFML
q = queryExecute(
    "SELECT * FROM posts WHERE published_at IS NOT NULL AND author_id IN ?",
    [ { value = '5,10,27', cfsqltype = 'CF_SQL_NUMERIC', list = true } ]
);

// qb
query = wirebox.getInstance('QueryBuilder@qb');
q = query.from('posts')
         .whereNotNull('published_at')
         .whereIn('author_id', [5, 10, 27])
         .get();

With Quick you can easily handle setting order by statements before the columns you want or join statements after a where clause:

query = wirebox.getInstance('QueryBuilder@qb');
q = query.from('posts')
         .orderBy('published_at')
         .select('post_id', 'author_id', 'title', 'body')
         .whereLike('author', 'Ja%')
         .join('authors', 'authors.id', '=', 'posts.author_id')
         .get();

// Becomes

q = queryExecute(
    "SELECT post_id, author_id, title, body FROM posts INNER JOIN authors ON authors.id = posts.author_id WHERE author LIKE ? ORDER BY published_at",
    [ { value = 'Ja%', cfsqltype = 'CF_SQL_VARCHAR', list = false, null = false } ]
);

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

Full Docs

You can browse the full documentation at https://qb.ortusbooks.com

Contributors

Thanks goes to these wonderful people (emoji key):


Eric Peterson

? ?

John Whish

? ?

Dan Murphy

? ?

Tim Brown

?

BluewaterSolutions

? ? ?

Tony Junkes

? ?

This project follows the all-contributors specification. Contributions of any kind welcome!

v5.5.0

07 Jun 2018 — 03:00: 22 UTC

feat

  • QueryBuilder: Add andWhere method for more readable chains. (309f4d8)

other

v5.4.1

27 Apr 2018 — 22:48: 54 UTC

fix

  • PostgresGrammar: Fix typo in getAllTableNames (91caf6a)
  • SchemaBuilder: Fix dropping foreign keys in MySQL (8895447)

other

v5.4.0

16 Apr 2018 — 21:36: 02 UTC

feat

  • AutoDiscover: Allow for runtime discovery (700948a)

other

v5.3.1

28 Mar 2018 — 22:12: 45 UTC

fix

  • ModuleConfig: Fix logic for determining CommandBox vs ColdBox environment (5c66466)

other

v5.3.0

26 Mar 2018 — 16:15: 55 UTC

chore

  • README: Update references to elpete to coldbox-modules (bc7c99c)

feat

  • ModuleConfig: Auto discover grammar by default. (b2347ae)

fix

  • ModuleConfig: Add PostgresGrammar alias to WireBox (eca03f0)

other

v5.2.1

14 Mar 2018 — 03:18: 19 UTC

fix

  • QueryBuilder: Preserve returnFormat when creating a new builder (4538947)

other

v5.2.0

12 Mar 2018 — 21:33: 37 UTC

feat

  • Grammar: Added official support for MSSQL, Oracle, and Postgres. (#34) (733dae3)

other

v5.1.2

20 Feb 2018 — 06:59: 54 UTC

other

perf

  • QueryBuilder: Replace normalizeToArray with simpler Array check (d54bcce)
  • BaseGrammar: Avoid isInstanceOf in wrapColumn (15042ce)

v5.1.1

19 Feb 2018 — 18:03: 58 UTC

fix

  • MySQLGrammar: Default to CURRENT_TIMESTAMP for timestamp columns (#32) (680750a)

other

v5.1.0

16 Feb 2018 — 22:23: 59 UTC

feat

  • SchemaBuilder: Add dropAllObjects action. (#31) (c3e23b5)

other

v5.0.3

16 Feb 2018 — 21:10: 33 UTC

chore

  • build: Enable commandbox-semantic-release (0fe689f)

errors

  • schema: Better error message when passing in a TableIndex to create column (f91a3f7)

other

  • *: Updated API Docs (dfd9510)
  • *: Update references from Builder to QueryBuilder (632e697)
  • *: Updated API Docs (8325db5)

 

 
$ box install qb
No collaborators yet.
  • Dec 07 2016 01:03 PM
  • Jun 06 2018 10:00 PM
  • 1759
  • 0
  • 1290