不要怂,就是干,撸起袖子干!

Commit b6c9117f by Yaroslav Admin Committed by Sushant

fix(types): add basic support for `bind` in sequelize.query() method (#10694)

1 parent cc765cc8
...@@ -5,6 +5,8 @@ import QueryTypes = require('./query-types'); ...@@ -5,6 +5,8 @@ import QueryTypes = require('./query-types');
import { Sequelize, RetryOptions } from './sequelize'; import { Sequelize, RetryOptions } from './sequelize';
import { Transaction } from './transaction'; import { Transaction } from './transaction';
type BindOrReplacements = { [key: string]: unknown } | unknown[];
/** /**
* Interface for query options * Interface for query options
*/ */
...@@ -40,9 +42,13 @@ export interface QueryOptions extends Logging, Transactionable { ...@@ -40,9 +42,13 @@ export interface QueryOptions extends Logging, Transactionable {
* Either an object of named parameter replacements in the format `:param` or an array of unnamed * Either an object of named parameter replacements in the format `:param` or an array of unnamed
* replacements to replace `?` in your SQL. * replacements to replace `?` in your SQL.
*/ */
replacements?: { replacements?: BindOrReplacements;
[key: string]: string | number | string[] | number[];
} | string[]; /**
* Either an object of named parameter bindings in the format `$param` or an array of unnamed
* values to bind to `$1`, `$2`, etc in your SQL.
*/
bind?: BindOrReplacements;
/** /**
* Force the query to use the write pool, regardless of the query type. * Force the query to use the write pool, regardless of the query type.
......
...@@ -35,4 +35,12 @@ sequelize.transaction<void>(async transaction => { ...@@ -35,4 +35,12 @@ sequelize.transaction<void>(async transaction => {
transaction, transaction,
logging: true, logging: true,
}) })
}) });
sequelize.query('SELECT * FROM `user` WHERE status = $1',
{ bind: ['active'], type: QueryTypes.SELECT }
);
sequelize.query('SELECT * FROM `user` WHERE status = $status',
{ bind: { status: 'active' }, type: QueryTypes.SELECT }
);
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!