Sequelize.query() method
Runs a raw statement, honouring a returning column list.
Signature:
query(sqlQuery: string | {
query: string;
values: any[];
}, options?: QueryOptions | QueryOptionsWithType<QueryTypes.RAW>): Promise<any>;
Parameters
|
Parameter |
Type |
Description |
|---|---|---|
|
sqlQuery |
string | { query: string; values: any[]; } |
The statement, or a statement with its bind values. |
|
options |
QueryOptions | QueryOptionsWithType<QueryTypes.RAW> |
(Optional) Query options, where |
Returns:
Promise<any>
Whatever sequelize's own query() returns for these options.
Remarks
Given a non-empty returning array, the RETURNING * in the statement is rewritten to name exactly those columns, and every returned model instance remembers the list, so serializing it emits only those properties. Everything else is sequelize's own query().
The rewrite is textual and looks for RETURNING * specifically, so a statement that already names its columns is left alone — and one that has no RETURNING at all is not given one.