QueryBuilder

Provides a nice way of writing queries in D, as well as some handy shortcuts to working with D structures in the DB.

Most method names are synonimous with the same keyword in SQL, but their order does not matter.

All of the methods can be chained.

Constructors

this
this(ref Connection connection)

Constructs a new QueryBuilder with the Connection, so we can directly run queries with it.

Members

Aliases

and
alias and = where

Alias and to where, to allow stuff like User.where( ... ).and( ... )

Functions

from
QueryBuilder from(string from)

Sets the builder's FROM value to the given string.

from
QueryBuilder from()

Same as above, but instead of accepting a string parameter, it instead accepts a type as a template parameter, then sets the value to that type's relation name. Preferred over the above version.

limit
QueryBuilder limit(int limit)

Sets the LIMIT in the query. Only for SELECT queries, obviously.

offset
QueryBuilder offset(int offset)

OFFSET for queries

opIndexAssign
void opIndexAssign(T val, string key)

Remembers the given key value pair, replacing the placeholders in the query before running it.

order
QueryBuilder order(string col, Order order)

Sets the ORDER part of the query. Accepts a column name and an Order value.

select
QueryBuilder select(string[] cols...)

Sets the builder's type to SELECT, a variadic array of column names to select

select
QueryBuilder select(Column[] cols...)

Same as above, except it accepts a variadic array of Column type. Mostly used internally.

select
QueryBuilder select()

Selects all the given relation's properties

where
QueryBuilder where(T[string] filters)

Adds new filter(s). Param placeholders are used, with the same names as the AA keys. Calling this multiple times will AND the filters.

where
QueryBuilder where(string filter, T params)

Adds a new custom filter.

Properties

or
QueryBuilder or [@property getter]

Once called, all additional parameters will be placed into their own group, OR placed between each group of ANDs

Examples

1 auto qb = QueryBuilder()
2 		.select("id")
3 		.from!User
4 		.where("posts > {posts}") // placeholders can be used 
5 		.order("posts", Order.desc)
6 		.limit(5);
7 
8 // Placeholders will be replaced ONLY if they are specified.
9 // No need to escape anything, as it sent with execParams
10 qb["posts"] = 50;

Meta