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(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

addParam
void addParam(T val)
Undocumented in source. Be warned that the author may not have intended to support it.
addParams
QueryBuilder addParams(T vals)
Undocumented in source. Be warned that the author may not have intended to support it.
addValue
QueryBuilder addValue(T val)
Undocumented in source. Be warned that the author may not have intended to support it.
addValues
QueryBuilder addValues(U val)
Undocumented in source. Be warned that the author may not have intended to support it.
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.

insert
QueryBuilder insert(string table, string[] cols)
Undocumented in source. Be warned that the author may not have intended to support it.
insert
QueryBuilder insert(string table, Column[] cols)
Undocumented in source. Be warned that the author may not have intended to support it.
limit
QueryBuilder limit(int limit)

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

offset
QueryBuilder offset(int offset)

OFFSET for queries

opBinary
QueryBuilder opBinary(T val)
Undocumented in source. Be warned that the author may not have intended to support it.
opIndexAssign
void opIndexAssign(T val, string key)

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

or
QueryBuilder or()

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

order
QueryBuilder order(string col, Order order)

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

query
Query query()
Undocumented in source. Be warned that the author may not have intended to support it.
query
Query query(Connection conn)
Undocumented in source. Be warned that the author may not have intended to support it.
remove
QueryBuilder remove()
Undocumented in source. Be warned that the author may not have intended to support it.
remove
QueryBuilder remove(string table)
Undocumented in source. Be warned that the author may not have intended to support it.
remove
QueryBuilder remove()
Undocumented in source. Be warned that the author may not have intended to support it.
returning
QueryBuilder returning(string[] ret)
Undocumented in source. Be warned that the author may not have intended to support it.
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

set
QueryBuilder set(T[string] params)
Undocumented in source. Be warned that the author may not have intended to support it.
set
QueryBuilder set(string col, T val)
Undocumented in source. Be warned that the author may not have intended to support it.
set
QueryBuilder set(string set)
Undocumented in source. Be warned that the author may not have intended to support it.
update
QueryBuilder update(string table)
Undocumented in source. Be warned that the author may not have intended to support it.
update
QueryBuilder update()
Undocumented in source. Be warned that the author may not have intended to support it.
values
QueryBuilder values(T vals)
Undocumented in source. Be warned that the author may not have intended to support it.
values
QueryBuilder values(Value[] vals)
Undocumented in source. Be warned that the author may not have intended to support it.
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

command
string command [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
dup
QueryBuilder dup [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.

Examples

auto qb = QueryBuilder()
      .select("id")
      .from!User
      .where("posts > {posts}") // placeholders can be used
      .order("posts", Order.desc)
      .limit(5);

// Placeholders will be replaced ONLY if they are specified.
// No need to escape anything, as it sent with execParams
qb["posts"] = 50;

Meta