Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Correctly wrap CTE expressions with parenthesis when required in certain grammars.
SchemaBuilder
can now be configured with default query options. (Default options will still be overridden by options passed to each SchemaBuilder
method.)
Add a reset
method to QueryBuilder.
Add locking helpers such as lock
, noLock
, lockForUpdate
, and sharedLock
.
Correct return aggregate values for date values from max
and min
executors.
Automatically add a scale
to an incoming query param when needed.
Add a whereNotLike
shortcut method.
Correctly format a COUNT(DISTINCT column)
query.
Only use bulk insert syntax when needed in OracleGrammar due to interactions between the result
parameter to cfquery
, Lucee, and the Oracle JDBC driver.
Add support for stored computed columns and virtual computed columns.
Swap master
branch to main
branch.
Remove unnecessary injection for QueryUtils.
Account for raw expressions when generating mementos for comparison
Add support for mediumtext & longtext types for MySQLGrammar.
Fix limit on simplePaginate.
Migrate release process to GitHub Actions.
Add a simplePaginate
pagination method for quicker performance when total records or total pages are not needed or too slow.
Introduce a numericSQLType
setting to specify the default numeric SQL type.
Default to html
for the dump
format argument to writeDump
.
Correctly use the passed in strictDateDetection
to the QueryUtils.cfc
.
Added a dump
command to aid in debugging a query while chaining.
orderByRaw
now can accept bindings.
A new, optional strictDateDetection
setting is available to check the underlying Java class of a date object instead of using isDate
.
Ignore select bindings for aggregate queries.
Allow spaces in table aliases.
Split FLOAT and DECIMAL column types in SQL Server.
Clear orderBy bindings when calling clearOrders
.
Trim table definitions before searching for aliases. Makes qb more lenient with extra whitespace.
when
callbacks now automatically scope and group where clauses when an OR
combinator is used.
Combine clearOrders
and orderBy
with a new reorder
method.
Clear current selected columns with clearSelect
.
Combine clearSelect
and either select
or selectRaw
with reselect
and reselectRaw
respectively.
Expose nested where functions to enable advanced query manipulation in downstream libraries like Quick.
Fixes for OracleGrammar including table aliases and wrapped subqueries.
Allow nullable timestamps in MySQL.
Return 0 on null aggregates.
Match type hints to documentation for join functions
Handle enhanced numeric checks with Secure Profile enabled.
Allow raw statements in basic where clauses.
Allow for space-delimited sort directions like column DESC
.
value
and values
now work with column formatters.
Correctly format RETURNING clauses with column formatters and ignoring table qualifiers.
Handle multi-word columns in queryRemoveColumns
.
Remove elvis operator due to ACF compatibility issues
Add support for MONEY and SMALLMONEY data types to SchemaBuilder.
Fix wrapping of enum types for Postgres.
Compatibility fix for ACF 2018 and listLast
parsing.
Include current_timestamp default for timestamp
columns in SchemaBuilder.
Ignore table qualifiers for insert and update.
Fix a bug with preventDuplicateJoins when using the closure syntax with a join.
Add executionTime to the data output from BaseGrammar, including being available in interceptors.
Fix a case where a column was not wrapped correctly when a where
used a subquery for the value.
Avoid duplicate
function due to cbORM / Hibernate bugs when used in the same application.
Split off a private whereBasic
method. This is used in Quick to provide extra sql type features.
Add a clearOrders
method. Any already configured orders are cleared. Any orders added after this call will be added as normal.
selectRaw
now can take an array of expressions.
Fixed an issue using column formatters with update
and insert
.
Using a new preventDuplicateJoins
setting in the module settings, qb can detect duplicate joins and ignore them. This is especially useful in a heavily filtered and dynamic query where you may or may not need the join at all or more than one column may need the same join. preventDuplicateJoins
defaults to false
, so it is opt-in. It may be turned on by default in a future breaking release of qb.
Enhance order by's with more direction options (c767ac8)
You can now use two shortcut methods: orderByAsc
and orderByDesc
. Additionally, orderBySub
or using orderBy
with a closure or builder instance will respect the direction argument.
Fix using whereBetween
with query param structs (07c9b72)
Ignore orders in aggregate queries (39e1338)
Format with cfformat (dc2a9b6)
Improve column wrapping with trimming (d98a5cb)
Prefer the parent query over magic methods when the parent query has the exact method. (f9fd8d1)
Switch to using ForgeBox Storage.
Allow passing query options in to paginate (cdecfb3)
Fix for inserting null values directly (1de27a6)
Use cfformat for automatic formatting (119e434)
Add a type to the onMissingMethod exception (90d1093)
Correctly wrap comments in MySQLGrammar
.
Publish qb apidocs to Ortus API Docs.
Fix for null values breaking the new checkIsActuallyNumeric
method in QueryUtils
.
Add a parameterLimit
public property to SqlServerGrammar
. This property is used in Quick to split up eager loading to work around the 2100 param limit of SQL Server.
Allow a parent query to be set. A parent query will receive any method calls that are not found on the Query Builder instance. This is especially useful for instances like Quick to allow Quick features like scopes to be available inside any closures.
Lambdas (arrow functions) are now allowed wherever closures are allowed.
Add an orderByRaw
method.
Please see the Migration Guide for more information on these changes.
Drop support for Lucee 4.5 and Adobe ColdFusion 11.
MSSQLGrammar
renamed to SqlServerGrammar
Remove variadic parameters support in builder functions like select
.
The defaultGrammar
mapping needs to be the full WireBox mapping, including the @qb
, if needed.
For instance, MSSQLGrammar
would become MSSQLGrammar@qb
.
This will allow for other grammars to be more easily contributed via third party modules.
The argument names of forPage
changed to match the new paginate
method.
Add defaultValue
and optional exception throwing to value
. (This changed the argument order.)
All methods that could conceivably take a subquery as well as a value now accept a closure or another builder instance to use as a subquery. (This changed the argument names in some instances.)
Completely revamped documentation! (You're looking at it right now.)
Add new flag to toSQL( showBindings = true )
to replace question marks (?
) with cfqueryparam
-compatible structs for debugging.
Preserve column case and order when converting a query to an array using the default "array"
return format.
Add a new paginate method to generate a pagination struct alongside the results. This can be customized using a custom PaginationCollector.
Allow raw values in insert
calls.
Allow default queryExecute
options
to be configure at a Query Builder level. This also enables custom QueryBuilders
a la Hyper.
Add a whereLike
method.
Allow closures to be used in left and right joins.
Provide an addUpdate
method to programmatically build the SET
clause of an update query.
Add a new chunk
method to grab records from the database in small sets.
Add raw
in alterTable
segments.
Add dropAllObjects
support for SqlServerGrammar
and OracleGrammar
to support migrate fresh
from cfmigrations.
Add a renameTable
alias for rename
.
Remove default constraints when dropping columns with a default on SqlServerGrammar
.
Add more column types and column helpers to SchemaBuilder
, including:
datetimeTz
lineString
nullableTimestamps
point
polygon
softDeletes
softDeletesTz
timeTz
timestamps
timestampTz
timestampsTz
withCurrent
Allow Expressions (query.raw
) in update statements.
We welcome all types of contributions!
The most common type of contribution is to fix an incorrect SQL generation for a database grammar.
To debug what SQL is being ran, you can always call toSQL
on any QueryBuilder
or SchemaBuilder
object. Additionally, you can listen to the preQBExecute
interception point for the generated SQL.
Each of the database grammars have two tests — {Grammar}QueryBuilderSpec.cfc
and {Grammar}SchemaBuilderSpec.cfc
. These tests run the same qb syntax across the different grammars. In each test are methods that return SQL strings like so:
If you find an issue with the SQL generated from a grammar, please file a pull request with the correct SQL in these tests. It's okay if you don't submit a fix as well. (But we'd greatly appreciate it!) Doing so will help expedite the fix.
If you want to add support for a new database grammar, simply copy these two tests from an existing grammar, rename them, change the getBuilder
method to return your new grammar, and fill out the SQL as it should be. That will guide your implementation to be 100% compatible with the other grammars in qb.
Using qb, you can:
Quickly scaffold simple queries
Make complex, out-of-order queries possible
Abstract away differences between database engines
Adobe ColdFusion 2016+
Lucee 5+
qb supports four major database grammars:
MySQL (MySQLGrammar
)
Oracle (OracleGrammar
)
Postgres (PostgresGrammar
)
Microsoft SQL Server (SqlServerGrammar
)
The Box modules discussion group and community can be found here:
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!
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:
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
.
The grammars provided by qb are:
MySQLGrammar
OracleGrammar
PostgresGrammar
SqlServerGrammar
If you are not using WireBox, just make sure to wire up the Builder
object with the correct grammar:
QB binds all parameters by default and guesses the SQL type based on passed values. The default SQL type for numeric values is CF_SQL_NUMERIC
, which is a floating point number, for the widest compatibility. This can cause performance problems with large recordsets in some database engines. You can provide a different default in coldbox.cfc if you wish to override this setting:
Note: These instructions assume a basic knowledge of FW/1, a working FW/1 application structure with qb installed in the
/subsystems
directory (manually or via CommandBox), and a database configured to run with your application.
Once the application structure is setup, now we need to wire up qb to a bean factory using DI/1.
First we will add a mapping in Application.cfc
.
Next we need to tell DI/1 where qb's components are and how to reference them for later use in the application. We can do so by defining the configuration settings in the variables.framework.subsystems
struct in Application.cfc
. The example below makes use of a load listener to declare each component instance and pass in any constructor arguments.
Now that everything is configured, you can launch your application with CommandBox by entering start
in the terminal or use whatever method you're accustomed to.
To access qb from your application's code, you can call on it by using getBeanFactory()
.
This isn't a breaking change that will affect most people. In fact, it will most likely improve your code.
Would generate the following SQL:
The problem with this statement is that the OR
can short circuit the active
check.
The fix is to wrap the LIKE
statements in parenthesis. This is done in qb using a function callback to where
.
When using the when
control flow function, it was easy to miss this. This is because you are already in a closure - it looks the same as when using where
to group the clauses.
In qb 8.0.0, when
will automatically group added where clauses when needed. That means our original example now produces the SQL we probably expected.
Grouping is not needed if there is no OR
combinator. In these cases no grouping is added.
If you had already wrapped your expression in a group inside the when
callback, nothing changes. Your code works as before. The OR
combinator check only works on the top most level of added where clauses.
Additionally, if you do not add any where clauses inside a when
callback, nothing changes from qb 7.
The breaking change part is if you were relying on these statements residing at the same level without grouping. In those cases, you may pass the withoutScoping
flag to the when
callback.
Support for Lucee 4.5 and Adobe ColdFusion 11 has been dropped. If you need support for these engines, please remain on an earlier version of qb.
MSSQLGrammar
was visually too close to MySQLGrammar
and was hard to differentiate quickly. SqlServerGrammar
is much more unique and easily identifiable. Additionally, more people that use this library refer to their database engine as "SQL Server" than "MSSQL".
Variadic parameter support was the ability to pass any number of arguments to certain methods like select
.
This code came with a slight performance cost and readability cost. That, combined with the fact that the above syntax is very close to an array, we are dropping support for variadic parameters. To migrate, wrap instances of variadic parameters in an array:
In previous versions, the value passed to defaultGrammar
was used to look up a mapping in the @qb
namespace. This made it difficult to add or use grammars that weren't part of qb. (You could get around this be registering your custom grammar in the @qb
namespace, but doing so seemed strange.)
To migrate this code, change your defaultGrammar
to be the full WireBox mapping in your moduleSettings
:
A defaultValue
parameter and optional exception throwing was added to value
. This pushed the options
struct to the end of the method. If you are using positional parameters with value
, you will need to update your method calls to either use named parameters or the new positions.
callback
to query
All methods that could conceivably take a subquery as well as a value now accept a closure or another builder instance to use as a subquery. This led to changing the callback
argument to query
in the following cases:
whereSub
whereInSub
whereExists
orWhereExists
whereNotExists
andWhereNotExists
orWhereNotExists
whereNullSub
orderBySub
subSelect
If you are using named parameters with any of the above methods you will need to migrate your method calls.
Version v5.0.0
brings support for SchemaBuilder
inside qb
. To avoid naming confusion, Builder
was renamed to QueryBuilder
. Any references in your code to Builder@qb
need to be updated to QueryBuilder@qb
.
qb is a fluent query builder for CFML. It is heavily inspired by from .
Installation is easy through and . Simply type box install qb
to get started.
Here's a gist with an example of the powerful models you can create with this!
Installation is easy through and . Simply type box install qb
to get started.
Previously, when using the control flow function, you were fully responsible for the wrapping of your where statements. For example, the following query:
To migrate, replace any instances of MSSQLGrammar
with SqlServerGrammar
. Make sure to also append the @qb
namespace, if needed,
A query builder is a stateful, transient object. That means that if you want to execute two different queries, you need two separate instances of QueryBuilder
.
As such, be careful when injecting QueryBuilder in to a component. If the component is a singleton, you will need to create the QueryBuilder inline or use a provider. This applies to ColdBox handlers as well.
While the above may seem innoculous, it can run in to issues as multiple requests come in to your application. Each request is sharing the same query builder instance and subsequent requests will have unintended results as the where
clause keeps growing request after request.
The solution is to either create the QueryBuilder inline, ensuring that each request has its own query to execute:
Or to use a WireBox provider to create a new query each time it is accessed:
One caveat when using a WireBox Provider: WireBox Providers proxy methods on to a new instance of the provided mapping on all methods except get
. get
is a method on the Provider itself. If you call get
as the first method on a Provider it will return a new instance of QueryBuilder, not execute the query. In those (rare) cases you will need to call query.get().get()
.
Once you have access to a QueryBuilder instance, you can create a new query using the same datasource, utils, returnFormat, paginationCollector, columnFormatter, and defaultOptions as the current QueryBuilder instance.
Used to set the base table for the query.
You can optionally specify an alias for the table.
An alias for from
where you like how calling table
looks.
Sometimes you need more control over your from
clause in order to add grammar specific instructions, such as adding SQL Server table hints to your queries.
Since the fromRaw()
takes your string verbatim, it's important that you make sure your SQL declaration is escaped properly. Failure to properly escape your table names may result in SQL errors.
Using fromRaw
will most likely tie your code to a specific database, so think carefully before using the fromRaw
method if you want your project to be database agnostic.
Many database engines allow you to define User Defined Functions. For example, SQL Server allows you to define UDFs that will return a table. In these type of cases, it may be necessary to bind parameters to your from
clause.
You can bind parameters to the fromRaw()
method by passing a secondary argument that is an array of the parameters to bind.
Complex queries often contain derived tables. Derived tables are essentially a temporal table defined as a subquery in the from
statement.
In additional a function callback, a separate QueryBuilder
instance can be passed to the fromSub
method.
You may not always want to select all columns from a database table. You can influence the select list of a query with the following methods.
Individual columns can contain fully-qualified names (some_table.some_column
), table aliases (alias.some_column
), and even set column aliases themselves (some_column AS c
). The columns
argument can be a single column, a list of columns (comma-separated), or an array of columns.
When calling select
any previous columns are discarded. If you want to incrementally select columns, use the addSelect
method.
If you pass no columns to this method, it will default to "*"
.
Calling distinct will cause the query to be executed with the DISTINCT
keyword.
distinct
applies to the entire query, not just certain fields.
This method adds the columns passed to it to the currently selected columns.
If the QueryBuilder
is currently selecting all columns ("*"
) when this method is called, the incoming columns will becoming the only columns selected.
A shortcut to use a raw expression in the select clause.
The expression is added to the other already selected columns.
(To learn more about raw and expressions, check out the docs on Raw Expressions.)
The method lets you pass either a callback or a QueryBuilder
instance to be used as a subselect expression. If a callback is passed it will be passed a new query instance as the only parameter.
The subselect is added to the other already selected columns.
Clears out the selected columns for a query along with any configured select bindings.
Clears out the selected columns for a query along with any configured select bindings. Then sets a selection of columns to select from the query. Any valid argument to select
can be passed here.
Clears out the selected columns for a query along with any configured select bindings. Then adds an Expression or array of expressions to the already selected columns.
The orderBy
method seems simple but has a lot of depth depending on the type of arguments you pass in.
Calling orderBy
multiple times appends to the order list.
Calling orderBy
multiple times will append to the order list.
You can order with a subquery using either a function or a QueryBuilder instance.
Adds a where clause to a query.
Any of the following operators can be used in a where clause.
When using the "="
constraint, you can use a shortcut and define the value as the second argument.
To group where statements together, pass a function to the where clause as the only parameter.
This grouping can be nested as many levels as you require.
A Function or QueryBuilder can be used as a subselect expression when passed to value
.
Adds a where between clause to the query.
If a function or QueryBuilder is passed it is used as a subselect expression.
Adds a where clause to a query that compares two columns.
Just as with where
, when using "="
as the operator you can use a shorthand passing the second column in as the operator and leaving the second column null
.
Expressions
can be passed in place of either column.
Adds a where exists clause to the query.
It can be configured with a function.
It can also be configured with a QueryBuilder instance.
Adds a where in clause to the query.
The values passed to whereIn
can be a single value, a list of values, or an array of values.
Some database grammars have a hard limit on the number of parameters passed to a SQL statement. Keep this in mind while writing your queries.
If a list of values is passed in, it is converted to an array of values using a single comma (","
) delimiter.
Expressions
can be freely mixed in with other values.
A function or QueryBuilder instance can be passed to be used as a subquery expression instead of a list of values.
You may find a whereExists
method performs better for you than a whereIn
with a subquery.
Shorthand to add a raw SQL statement to the where clauses.
Adds a where null clause to the query.
qb uses onMissingMethod
to provide a few different helpers when working with where...
methods.
Every where...
method in qb can be called prefixed with either and
or or
. Doing so will call the original method using the corresponding combinator.
If you call a method starting with where
that does not match an existing qb method, qb will instead call the where
method using the rest of the method name as the first column name. (The rest of the arguments will be shifted to account for this.) This also applies to andWhere{Column}
and orWhere{Column}
method signatures.
Join clauses range from simple to complex including joining complete subqueries on multiple conditions. qb has your back with all of these use cases.
Applies a join to the query. The simplest join is to a table based on two columns:
When doing a simple join using =
as the operator, you can omit it and pass just the column names:
Using raw
will most likely tie your code to a specific database, so think carefully before using the raw
method if you want your project to be database agnostic.
When you need to specify more clauses to join, you can pass a function as the second argument:
Conditions inside a join clause can be grouped using a function.
Adds a join to another table based on a WHERE
clause instead of an ON
clause. WHERE
clauses introduce parameters and parameter bindings whereas on
clauses join between columns and don't need parameter bindings.
For simple joins, this specifies a column on which to join the two tables:
Using joinRaw
will most likely tie your code to a specific database, so think carefully before using the joinRaw
method if you want your project to be database agnostic.
Alternatively, a function may be used to define the derived table:
Complex join conditions are also possible by passing a function as the third parameter:
Using leftJoinRaw
will most likely tie your code to a specific database, so think carefully before using the leftJoinRaw
method if you want your project to be database agnostic.
Using rightJoinRaw
will most likely tie your code to a specific database, so think carefully before using the rightJoinRaw
method if you want your project to be database agnostic.
Uses the raw SQL provided to as the table for the cross join clause. Cross joins cannot be further constrained with on
or where
clauses.
Using crossJoinRaw
will most likely tie your code to a specific database, so think carefully before using the crossJoinRaw
method if you want your project to be database agnostic.
Applies a join condition to the JoinClause
. An alias for whereColumn
.
Applies a join condition to the JoinClause
using an or
combinator. An alias for orWhereColumn
.
You can optionally configure qb to ignore duplicate joins. With this setting turned on each JoinClause
is inspected and checked if it matches any existing JoinClause
instances on the query. This is useful if you have a table shared between optional constraints and want to ensure it is only added once.
You can opt-in to this behavior by setting preventDuplicateJoins = true
in your moduleSettings
in config/ColdBox.cfc
.
You can also provide an .
Clears the currently configured orders for the query. Usually used by downstream libraries like .
Clears the currently configured orders for the query and sets the new orders passed in. Any valid argument to can be passed here. Usually used by downstream libraries like .
Using the where
method will parameterize the value
passed. If you want to constrain a column to another column, use the method.
You can also pass an as the value.
You may also use statements to simplify this further.
This method is simply an alias for with the combinator set to "and"
.
This method is simply an alias for with the combinator set to "or"
.
Adds a where not in clause to the query. This behaves identically to the method with the negate
flag set to true
. See the documentation for for usage and examples.
Adds a where not in clause to the query. This behaves identically to the method with the negate
flag set to true
. See the documentation for for usage and examples.
A shortcut for calling with "like"
set as the operator.
A shortcut for calling with "not like"
set as the operator.
Any value in the list or array can also be passed using a to have more control over the parameter settings.
Adds a where not in clause to the query. This behaves identically to the whereIn
method with the negate
flag set to true
. See the documentation for for usage and examples.
Adds a where not in clause to the query. This behaves identically to the method with the negate
flag set to true
. See the documentation for for usage and examples.
`` are also supported as the table
argument (though you may prefer the readability of the method):
You can specify clauses in your joins as well.
A preconfigured can also be passed to the join function. This allows you to extract shared pieces of code out to different functions.
For complex joins, a function can be passed to first
. This allows multiple on
and where
conditions to be applied to the join. See the documentation for for more information.
Uses the raw SQL provided to as the table for the join clause. All the other functionality of joinRaw
matches the method. Additionally, there are , , and crossJoinRaw
methods available.
Adds a join to a derived table. All the functionality of the method applies to constrain the query. The derived table can be defined using a QueryBuilder
instance:
Uses the raw SQL provided to as the table for the left join clause. All the other functionality of leftJoinRaw
matches the method.
Adds a left join to a derived table. All the functionality of the method applies to define and constrain the query.
Uses the raw SQL provided to as the table for the right join clause. All the other functionality of rightJoinRaw
matches the method.
Adds a right join to a derived table. All the functionality of the method applies to define and constrain the query.
Adds a cross join to a derived table. The derived table can be defined using a QueryBuilder
instance or a function just as with . Cross joins cannot be constrained, however.
Creates a new . A is a specialized version of a QueryBuilder
. You may call on
or orOn
to constrain the . You may also call any methods.
Creating a directly is useful when you need to share a join between different queries. You can create and configure the in a function and pass it to queries as needed.
Although a can be passed to , , , and crossJoin
, the type of the will override the type of the function.
A JoinClause
is a specialized version of a QueryBuilder
. You may call on
or orOn
to constrain the JoinClause
. You may also call any methods.
Name
Type
Required
Default
Description
from
string | Expression
true
​
The name of the table or a Expression object from which the query is based.
Name
Type
Required
Default
Description
table
string | Expression
true
​
The name of the table or a Expression object from which the query is based.
Name
Type
Required
Default
Description
from
string
true
​
The sql snippet to use as the table.
bindings
array
false
[]
Any bindings needed for the expression.
Name
Type
Required
Default
Description
alias
string
true
​
The alias for the derived table.
input
Function | QueryBuilder
true
Either a QueryBuilder
instance or a closure to define the derived query.
Name
Type
Required
Default
Description
columns
string | array
false
​"*"
A single column, list of columns, or array of columns to retrieve.
Name
Type
Required
Default
Description
state
boolean
false
​true
Value to set the distinct flag.
Name
Type
Required
Default
Description
columns
string | array
true
​
A single column, list of columns, or array of columns to add to the select.
Name
Type
Required
Default
Description
expression
any
true
​
The raw expression for the select statement.
bindings
array
false
[]
Any bindings needed for the raw expression.
Name
Type
Required
Default
Description
alias
string
true
​
The alias for the subselect expression.
query
Function | QueryBuilder
true
The callback or query to use in the subselect.
Name
Type
Required
Default
Description
No arguments
``
Name
Type
Required
Default
Description
columns
string | array
false
​"*"
A single column, list of columns, or array of columns to retrieve.
Name
Type
Required
Default
Description
expression
any
true
​
The raw expression for the select statement.
bindings
array
false
[]
Any bindings needed for the raw expression.
Name | Type | Required | Default | Description |
column | any |
| The list of the columns to order by. Each column can optionally declare it's sort direction after a pipe delimiter. (e.g. `"height | desc"`). |
direction | string |
|
| The direction by which to order the query. Accepts |
Name | Type | Required | Default | Description |
column | any |
| The array of the columns to order by. Each column can optionally declare it's sort direction after a pipe delimiter. (e.g. `"height | desc"`). |
direction | string |
|
| The direction by which to order the query. Accepts |
Name | Type | Required | Default | Description |
column | any |
| The array of the columns to order by. Each column can optionally declare it's sort direction using a struct. The struct should have a column key and an optional direction key. (e.g. |
direction | string |
|
| The direction by which to order the query. Accepts |
Name | Type | Required | Default | Description |
expression | string |
| The raw SQL expression to use. |
bindings | array |
|
| Any bindings ( |
Name | Type | Required | Default | Description |
No arguments |
Valid Operators |
= | < | > |
<= | >= | <> |
!= | like | like binary |
not like | between | ilike |
& | | | ^ |
<< | >> | rlike |
regexp | not regexp | ~ |
~* | !~ | !~* |
similar to | not similar to |
Name | Type | Required | Default | Description |
operator | string |
|
| The boolean operator for the join clause. |
where | boolean |
|
| Sets if the value of |
Name | Type | Required | Default | Description |
operator | string |
|
| The boolean operator for the join clause. |
where | boolean |
|
| Sets if the value of |
Name | Type | Required | Default | Description |
Name | Type | Required | Default | Description |
table | string |
| ​ | The raw SQL string to use as the table. |
Name | Type | Required | Default | Description |
alias | string |
| The alias for the derived table. |
input | Function | QueryBuilder |
| ​ | Either a |
Name | Type | Required | Default | Description |
column | any |
|
direction | string |
|
| The direction by which to order the query. Accepts |
Name | Type | Required | Default | Description |
column | any |
|
direction | string |
|
| Ignored when using a Function or QueryBuilder instance. |
Name | Type | Required | Default | Description |
column | any |
|
direction | string |
|
| The direction by which to order the query. Accepts |
Table of Contents |
Name | Type | Required | Default | Description |
column |
|
operator |
| The operator to use for the constraint (i.e. "=", "<", ">=", etc.). A value can be passed as the |
value | any |
|
combinator | string |
|
|
Name | Type | Required | Default | Description |
column |
|
operator |
| The operator to use for the constraint (i.e. "=", "<", ">=", etc.). A value can be passed as the |
value | any |
|
Name | Type | Required | Default | Description |
column |
|
operator |
| The operator to use for the constraint (i.e. "=", "<", ">=", etc.). A value can be passed as the |
value | any |
|
Name | Type | Required | Default | Description |
column | string | Expression |
|
start | any | Function | QueryBuilder |
| The beginning value of the BETWEEN statement. If a function or QueryBuilder is passed it is used as a subselect expression. |
end | any | Function | QueryBuilder |
| The end value of the BETWEEN statement. If a function or QueryBuilder is passed it is used as a subselect expression. |
combinator | string |
|
|
negate | boolean |
|
| False for BETWEEN, True for NOT BETWEEN. |
Name | Type | Required | Default | Description |
column | string | Expression |
|
start | any | Function | QueryBuilder |
| The beginning value of the BETWEEN statement. If a function or QueryBuilder is passed it is used as a subselect expression. |
end | any | Function | QueryBuilder |
| The end value of the BETWEEN statement. If a function or QueryBuilder is passed it is used as a subselect expression. |
combinator | string |
|
|
Name | Type | Required | Default | Description |
first |
|
operator |
| The operator to use for the constraint (i.e. "=", "<", ">=", etc.). A value can be passed as the |
second | string | Expression |
|
combinator | string |
|
|
Name | Type | Required | Default | Description |
query | Function | QueryBuilder |
| A function or QueryBuilder instance to be used as the exists subquery. |
combinator | string |
|
|
negate | boolean |
|
| False for EXISTS, True for NOT EXISTS. |
Name | Type | Required | Default | Description |
query | Function | QueryBuilder |
| A function or QueryBuilder instance to be used as the not exists subquery. |
combinator | string |
|
|
Name | Type | Required | Default | Description |
column |
|
value | any |
|
combinator | string |
|
|
Name | Type | Required | Default | Description |
column |
|
value | any |
|
combinator | string |
|
|
Name | Type | Required | Default | Description |
column | string | Expression |
|
values |
|
combinator | string |
|
|
negate | boolean |
|
| False for IN, True for NOT IN. |
Name | Type | Required | Default | Description |
column | string | Expression |
|
values |
|
combinator | string |
|
|
Name | Type | Required | Default | Description |
sql | string |
| The raw SQL to add to the query. |
whereBindings | array |
|
|
combinator | string |
|
|
Name | Type | Required | Default | Description |
column | string | Expression |
|
combinator | string |
|
|
negate | boolean |
|
| False for NULL, True for NOT NULL. |
Name | Type | Required | Default | Description |
column | string | Expression |
|
combinator | string |
|
|
negate | boolean |