Skip to content
Oxford Harrison edited this page Nov 11, 2024 · 25 revisions

DOCSAPIDQLTabletable.select()


See also ➞ SELECT

Programmatically perform an SELECT query.

Syntax

table.select(
    fields?: Field[],
    modifiers?: QueryOptions | LimitClause | Callback,
): Promise<QueryResult>;
table.select(
    arg?: {
        fields?: Field[];
    } & QueryOptions | LimitClause | Callback
): Promise<QueryResult>;
Param Description
fields? Optional. List of fields to select. (See ➞ Field.) Defaults to all fields if omitted.
modifiers? Optional. Additional query modifiers, such as query clauses, or a callback that recieves the SelectStatement instance for building.
arg? Optional. Single parameter pattern.

QueryOptions

interface QueryOptions {
    where?: WhereClause;
    orderBy?: OrderByClause;
    groupBy?: GroupByClause;
    limit?: LimitClause;
}
Param Description
where? The WHERE clause. (See ➞ WhereClause, The WHERE Clause.)
orderBy? The ORDER BY clause. (See ➞ OrderByClause, The ORDER BY Clause)
groupBy? The GROUP BY clause. (See ➞ GroupByClause, The GROUP BY Clause)
limit? The LIMIT clause. (See ➞ LimitClause, The LIMIT Clause)

QueryResult

type QueryResult = Array<object> | object;
Type Description
Array<object> An array of objects by default.
object A single object—when it's find by ID.

Usage

Call Patterns

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

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
Clone this wiki locally