@loopback/docs
Version:
Documentation files rendered at [https://loopback.io](https://loopback.io)
118 lines (63 loc) • 2.18 kB
Markdown
---
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) > [@loopback/sequelize](./sequelize.md) > [SequelizeDataSource](./sequelize.sequelizedatasource.md) > [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
<table><thead><tr><th>
Parameter
</th><th>
Type
</th><th>
Description
</th></tr></thead>
<tbody><tr><td markdown="1">
command
</td><td markdown="1">
Command
</td><td markdown="1">
A parameterized SQL command or query.
</td></tr>
<tr><td markdown="1">
parameters
</td><td markdown="1">
NamedParameters \| PositionalParameters
</td><td markdown="1">
_(Optional)_ List of parameter values to use.
</td></tr>
<tr><td markdown="1">
options
</td><td markdown="1">
Options
</td><td markdown="1">
_(Optional)_ Additional options, for example `transaction`<!-- -->.
</td></tr>
</tbody></table>
**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
```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]
);
```