UNPKG

@loopback/docs

Version:

Documentation files rendered at [https://loopback.io](https://loopback.io)

58 lines (39 loc) 1.99 kB
--- lang: en title: 'API docs: sequelize.sequelizedatasource.execute' keywords: LoopBack 4.0, LoopBack 4, Node.js, TypeScript, OpenAPI sidebar: lb4_sidebar editurl: https://github.com/loopbackio/loopback-next/tree/master/extensions/sequelize permalink: /doc/en/lb4/apidocs.sequelize.sequelizedatasource.execute.html --- <!-- Do not edit this file. It is automatically generated by API Documenter. --> [Home](./index.md) &gt; [@loopback/sequelize](./sequelize.md) &gt; [SequelizeDataSource](./sequelize.sequelizedatasource.md) &gt; [execute](./sequelize.sequelizedatasource.execute.md) ## SequelizeDataSource.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:** ```typescript execute(command: Command, parameters?: NamedParameters | PositionalParameters, options?: Options): Promise<AnyObject>; ``` ## Parameters | Parameter | Type | Description | | --- | --- | --- | | command | [Command](./repository.command.md) | A parameterized SQL command or query. | | parameters | [NamedParameters](./repository.namedparameters.md) \| [PositionalParameters](./repository.positionalparameters.md) | _(Optional)_ List of parameter values to use. | | options | [Options](./repository.options.md) | _(Optional)_ Additional options, for example <code>transaction</code>. | **Returns:** Promise&lt;[AnyObject](./repository.anyobject.md)<!-- -->&gt; A promise which resolves to the command output. The output type (data structure) is database specific and often depends on the command executed. ## Example ```ts // MySQL const result = await db.execute( 'SELECT * FROM Products WHERE size > ?', [42] ); // PostgreSQL const result = await db.execute( 'SELECT * FROM Products WHERE size > $1', [42] ); ```