-
-
Notifications
You must be signed in to change notification settings - Fork 2
table.select()
Oxford Harrison edited this page Nov 13, 2024
·
25 revisions
Programmatically perform a SELECT
query.
See related ➞
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 |
Optional list of fields to select. Defaults to all fields if omitted. |
modifiers? |
QueryOptions LimitClause
|
Optional additional query modifiers. Can be Callback —a callback function that recieves the underlying SelectStatement instance for manipulation. |
arg? |
Field QueryOptions LimitClause
|
Optional argument for a single-parameter call pattern. Can be Callback —a callback function that recieves the underlying SelectStatement instance for manipulation. |
interface QueryOptions {
where?: WhereClause;
orderBy?: OrderByClause;
groupBy?: GroupByClause;
limit?: LimitClause;
}
Param | Interfaces | Description |
---|---|---|
where? |
WhereClause |
An optional WHERE clause. |
orderBy? |
OrderByClause |
An optional ORDER BY clause. |
groupBy? |
GroupByClause |
An optional GROUP BY clause. |
limit? |
LimitClause |
An optional 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 a find-one query. |
Two-parameter call pattern:
// Fields list and query limit passed distinctly
const result = await table.select(['first_name', 'last_name', 'email'], 4);
Single-parameter call pattern:
// Fields list only
const result = await table.select(['first_name', 'last_name', 'email']);
// Query limit only
const result = await table.select(4);
// Fields list and query limit passed together
const result = await table.select({
fields: ['first_name', 'last_name', 'email'],
limit: 4
});
Zero-parameter call pattern:
// A SELECT * query
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: 4 }
);
console.log(result); // single result object
See also ➞ Magic Paths
Select a multi-dimensional record:
// Structured relational query | MANY-TO-ONE
// DESC: Tie-in structure from the users table
const result = await table.select(
[ 'title', 'content', { expr: {
path: ['author', { fields: ['name', 'email'] }]
}, as: 'author' } ],
{ where: { eq: [
{ path: ['author', '~>', 'role'] },
{ binding: ['admin'] }
] } }
);
See ➞ Magic Paths ➞ Example 2