SelectOperation

This is the builder struct that's used for select operations (queries)

Don't construct this struct manually, use the db.select or tx.select method (UFCS method defined globally) to create this struct.

Methods you can call on this builder to manipulate the result:

The following methods are implemented for restricting queries: (most can only be called once, which is enforced through the template parameters) - condition is used to set the "WHERE" clause in SQL. It can only be called once on any query operation. - limit can be used to set a maximum number of rows to return. When this restriction is called, findOne and findOptional can no longer be used. - offset can be used to offset after how many rows to start returning. - orderBy can be used to order how the results are to be returned by the database.

The following methods are important when working with ModelRef / foreign keys: - populate eagerly loads data from a foreign model, (re)using a join

Finishing methods you can call on this builder:

The following methods can be used to extract the data: - stream to asynchronously stream data. (can be used as iterator / range) - array to eagerly fetch all data and do a big memory allocation to store all the values into. - findOne to find the first matching item or throw for no data. - findOptional to find the first matching item or return Nullable!T.init for no data.

There are restrictions when stream/array as well as when findOne/findOptional can be used:

stream/array are usable when: - neither limit and offset are set - both limit and offset are set - only limit is set and offset is not set

findOne/findOptional are only usable when no limit is set.

Postblit

this(this)
this(this)
Undocumented in source.

Members

Aliases

ConditionBuilderCallback
alias ConditionBuilderCallback = Condition delegate(ConditionBuilder!T)

Argument to condition. Callback that takes in a ConditionBuilder!T and returns a Condition that can easily be created using that builder.

OrderBuilderCallback
alias OrderBuilderCallback = ffi.FFIOrderByEntry delegate(OrderBuilder!T)

Argument to orderBy. Callback that takes in an OrderBuilder!T and returns the ffi ordering value that can be easily created using the builder.

PopulateBuilderCallback
alias PopulateBuilderCallback = PopulateRef[] delegate(PopulateBuilder!T)

Argument to populate. Callback that takes in an OrderBuilder!T and returns the ffi ordering value that can be easily created using the builder.

Functions

array
TSelect[] array()

Fetches all result data into one array. Uses the GC to allocate the data, so it's not needed to keep track of how long objects live by the user.

condition
SelectOperation!(T, TSelect, true, hasOffset, hasLimit) condition(ConditionBuilderCallback callback)

Limits the query to only rows matching this condition. Maps to the WHERE clause in an SQL statement.

findOne
TSelect findOne()

Returns the first row of the result data or throws if no data exists.

findOptional
Nullable!TSelect findOptional()

Returns the first row of the result data or throws if no data exists.

limit
SelectOperation!(T, TSelect, hasWhere, hasOffset, true) limit(ulong limit)

Sets the maximum number of rows to return. Using this method disables the findOne and findOptional methods.

offset
SelectOperation!(T, TSelect, hasWhere, true, hasLimit) offset(ulong offset)

Sets the offset. (number of rows after which to return from the database)

opIndex
SelectOperation!(T, TSelect, hasWhere, true, true) opIndex(ulong[2] slice)

Implementation detail, makes it possible to use [start .. end] on the select struct to set both offset and limit at the same time.

opSlice
ulong[2] opSlice(ulong start, ulong end)

Implementation detail, makes it possible to use [start .. end] on the select struct to set both offset and limit at the same time.

orderBy
typeof(this) orderBy(OrderBuilderCallback callback)

Allows ordering by the specified field with the specified direction. (defaults to ascending)

populate
typeof(this) populate(PopulateBuilderCallback callback)

Eagerly loads the data for the specified foreign key ModelRef fields when executing the query.

range
SelectOperation!(T, TSelect, hasWhere, true, true) range(ulong start, ulong endExclusive)

Implementation detail, makes it possible to use [start .. end] on the select struct to set both offset and limit at the same time.

stream
auto stream()

Fetches all data into a range that can be iterated over or processed with regular range functions. Does not allocate an array to store the fetched data in, but may still use sparingly the GC in implementation.

Meta