Page Contents

Home > @loopback/repository > DefaultCrudRepository > execute

DefaultCrudRepository.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.


execute(command: Command, parameters: NamedParameters | PositionalParameters, options?: Options): Promise<AnyObject>;


Parameter Type Description
command Command A parameterized SQL command or query. Check your database documentation for information on which characters to use as parameter placeholders.
parameters NamedParameters | PositionalParameters List of parameter values to use.
options Options (Optional) Additional options, for example transaction.



A promise which resolves to the command output as returned by the database driver. The output type (data structure) is database specific and often depends on the command executed.


// MySQL
const result = await repo.execute(
  'SELECT * FROM Products WHERE size > ?',

// PostgreSQL
const result = await repo.execute(
  'SELECT * FROM Products WHERE size > $1',