Page Contents
Home > @loopback/sequelize > SequelizeCrudRepository > execute
SequelizeCrudRepository.execute() method
Execute a SQL command.
**WARNING:** In general, it is always better to perform database actions through repository methods. Directly executing SQL may lead to unexpected results, corrupted data, security vulnerabilities and other issues.
Signature:
execute(command: Command, parameters?: NamedParameters | PositionalParameters, options?: Options): Promise<AnyObject>;
Parameters
Parameter | Type | Description |
---|---|---|
command | Command | A parameterized SQL command or query. |
parameters | NamedParameters | PositionalParameters | (Optional) List of parameter values to use. |
options | Options | (Optional) Additional options, for example transaction . |
Returns:
Promise<AnyObject>
A promise which resolves to the command output. The output type (data structure) is database specific and often depends on the command executed.
Example
// MySQL
const result = await repo.execute(
'SELECT * FROM Products WHERE size > ?',
[42]
);
// PostgreSQL
const result = await repo.execute(
'SELECT * FROM Products WHERE size > $1',
[42]
);