-
-
Notifications
You must be signed in to change notification settings - Fork 2
table.select()
Oxford Harrison edited this page Nov 10, 2024
·
25 revisions
Programmatically perform an SELECT
query.
table.select(
fields?: Field[],
modifiers?: QueryOptions | Limit | Callback,
): Promise<QueryResult>;
table.select(
arg?: {
fields?: Field[];
} & QueryOptions | Limit | Callback
): Promise<QueryResult>;
type Field =
| string
| { expr: any, as?: string }
| Function;
interface QueryOptions {
where?: any;
limit?: Limit;
}
type Limit = number;
type Callback = function;
type QueryResult = Array<object> | object;
Param | Description |
---|---|
fields? |
Fields list. |
modifiers? |
Query modifiers. |
└ QueryOptions
Param | Description |
---|---|
where |
The where clause. |
limit |
The limit clause. |
- A Savepoint instance (See ➞
Savepoint
) or the booleantrue
when savepoint creation has been disabled viaoptions.noCreateSavepoint
; (Compare ➞ Query Return Value)
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 column 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