-
-
Notifications
You must be signed in to change notification settings - Fork 2
table.select()
Oxford Harrison edited this page Nov 11, 2024
·
25 revisions
DOCS • API • DQL • Table •
table.select()
Programmatically perform an SELECT
query.
See also ➞
SELECT
table.select(
fields?: Field[],
modifiers?: QueryOptions | LimitClause | Callback,
): Promise<QueryResult>;
table.select(
arg?: {
fields?: Field[];
} & QueryOptions | LimitClause | Callback
): Promise<QueryResult>;
Param | Interfaces | Description |
---|---|---|
fields? |
Field |
List of fields to select. Defaults to all fields if omitted. |
modifiers? |
QueryOptions LimitClause
|
Additional query modifiers. Can be Callback —a callback function that recieves the SelectStatement instance for building. |
arg? |
Field QueryOptions LimitClause
|
Argument for a single parameter pattern. Can be Callback —a callback function that recieves the SelectStatement instance for building. |
interface QueryOptions {
where?: WhereClause;
orderBy?: OrderByClause;
groupBy?: GroupByClause;
limit?: LimitClause;
}
Param | Interfaces | Description |
---|---|---|
where? |
WhereClause |
The WHERE clause. |
orderBy? |
OrderByClause |
The ORDER BY clause. |
groupBy? |
GroupByClause |
The GROUP BY clause. |
limit? |
LimitClause |
The LIMIT clause. |
type QueryResult = Array<object> | object;
Type | Interfaces | Description |
---|---|---|
Array<object> |
- | An array of objects—the default query result. |
object |
- | A single object—the result of find by ID. |
Two-parameter call pattern:
/**
* SELECT first_name, last_name, email
* LIMIT 4
*/
const result = await table.select(['first_name', 'last_name', 'email'], 4);
Single-parameter call pattern:
/**
* SELECT first_name, last_name, email
*/
const result = await table.select(['first_name', 'last_name', 'email']);
/**
* SELECT *
* LIMIT 4
*/const result = await table.select(4);
/**
* SELECT first_name, last_name, email
* LIMIT 4
*/
const result = await table.select({
fields: ['first_name', 'last_name', 'email'],
limit: 4
});
Zero-parameter call pattern:
/**
* SELECT *
*/
const result = await table.select();
Find by ID—with actual ID name automatically figured by Linked QL:
/**
* SELECT *
* WHERE automatically_figured_primary_key_name = 4
*/
const result = await table.select({ where: 1 });
console.log(result); // single result object