5.1 KiB
| sidebar_position |
|---|
| 3 |
Select
Performs a query to retrieve data from a table.
Methods
selectDatabase()
→ (database = String) → this
Selects a different database for this query.
Parameters
| Parameter | Type | Description |
|---|---|---|
database |
String | Name 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
| Parameter | Type | Description |
|---|---|---|
string |
String | The where-clause as a string with ? representing each values. |
values |
Array<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
| Parameter | Type | Description |
|---|---|---|
string |
String | The having-clause with possible aggregation ? representing each values. |
values |
Array<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
| Parameter | Type | Description |
|---|---|---|
column |
String | Column to order by |
desc |
Boolean | Sort descending? Defaults to false |
aggregation |
Enum → MIN/MAX/COUNT/SUM/AVG |
The aggregation type to use |
Returns
→ this
count()
→ (doParse = Boolean) → this
Counts the number of entries of the first selected column.
Parameters
| Parameter | Type | Description |
|---|---|---|
doParse |
Boolean | If 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
| Parameter | Type | Description |
|---|---|---|
doParse |
Boolean | If 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
| Parameter | Type | Description |
|---|---|---|
doParse |
Boolean | If 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
| Parameter | Type | Description |
|---|---|---|
...columns |
String | The 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
| Parameter | Type | Description |
|---|---|---|
type |
Enum → LEFT/INNER/RIGHT/FULL OUTER |
The join type |
table |
String | Table to join on |
onOriginalColumn |
String | Column name on the original table to check agains |
onJoinedColumn |
String | Column name of the join table to check against |
...columns |
String | The 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
| Parameter | Type | Description |
|---|---|---|
number |
Number | Limits the query by specified rows |
offset |
Number | Offset to start at. |
Returns
→ this
pagination()
→ (page = Number, itemsPerPage = Number) → this
Paginates the query.
Parameters
| Parameter | Type | Description |
|---|---|---|
page |
Number | The page to get (Minimum 1) |
itemsPerPage |
Number | How many items a page should have |
Returns
→ this
execute()
async → () → any
Executes the prepared query.
Returns
→ any - Query result