Skip to main content

Select

Performs a query to retrieve data from a table.

Methods

selectDatabase()

→ (database = String) → this

Selects a different database for this query.

Parameters

ParameterTypeDescription
databaseStringName of the database to select

Returns

this


distinct()

→ () → this

Adds the 'distinct' keyword to this query

  • With 'distinct' only unique values are returned

Returns

this


where()

→ (string = String, values = Array<any>) → this

Adds a where-clause to the query

  • Values should be set as ? in the string and given in left-to-right order via the 'values'-array to minimize the risk of sql-injection
  • If you are using joins, specify the table and column together: table.column

Parameters

ParameterTypeDescription
stringStringThe where-clause as a string with ? representing each values.
valuesArray<any>Array containing values replacing the ? in the string (from left to right)

Returns

this


having()

→ (string = String, values = Array<any>) → this

Same as where() but allows for aggregation.

  • Values should be set as ? in the string and given in left-to-right order via the 'values'-array to minimize the risk of sql-injection
  • If you are using joins, specify the table and column together: table.column

Parameters

ParameterTypeDescription
stringStringThe having-clause with possible aggregation ? representing each values.
valuesArray<any>Array containing values replacing the ? in the string (from left to right)

Returns

this


order()

→ (column = String, desc = Boolean, aggregation = Enum) → this

Adds a new sort order.

  • Can be used multiple times to order by multiple columns

Parameters

ParameterTypeDescription
columnStringColumn to order by
descBooleanSort descending? Defaults to false
aggregationEnumMIN/MAX/COUNT/SUM/AVGThe aggregation type to use

Returns

this


count()

→ (doParse = Boolean) → this

Counts the number of entries of the first selected column.

Parameters

ParameterTypeDescription
doParseBooleanIf true the query will only return a Number of entries. Defaults to false.

Returns

this


sum()

→ (doParse = Boolean) → this

Sums numerical rows of the first selected column.

Parameters

ParameterTypeDescription
doParseBooleanIf true the query will only return a Number of entries. Defaults to false.

Returns

this


avg()

→ (doParse = Boolean) → this

Averages numerical rows of the first selected column.

Parameters

ParameterTypeDescription
doParseBooleanIf true the query will only return a Number of entries. Defaults to false.

Returns

this


group()

→ (...columns = String) → this

Groups rows that have the same values into summary rows.

Parameters

ParameterTypeDescription
...columnsStringThe columns to group by

Returns

this


join()

→ (type = Enum, table = String, onOriginalColumn = String, onJoinedColumn = String, ...columns = String) → this

Adds a new join to the query.

Parameters

ParameterTypeDescription
typeEnumLEFT/INNER/RIGHT/FULL OUTERThe join type
tableStringTable to join on
onOriginalColumnStringColumn name on the original table to check agains
onJoinedColumnStringColumn name of the join table to check against
...columnsStringThe columns to join. OG-columns must be set!

Returns

this


limit()

→ (number = Number, offset = Number) → this

Limits the query and specifies an offset to start at.

warning

offset has no default value and therefore must not be empty!

Parameters

ParameterTypeDescription
numberNumberLimits the query by specified rows
offsetNumberOffset to start at.

Returns

this


pagination()

→ (page = Number, itemsPerPage = Number) → this

Paginates the query.

Parameters

ParameterTypeDescription
pageNumberThe page to get (Minimum 1)
itemsPerPageNumberHow many items a page should have

Returns

this


execute()

async → () → any

Executes the prepared query.

Returns

any - Query result