Skip to content

Commit

Permalink
fix(types): add basic support for bind in sequelize.query() method (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
devoto13 authored and sushantdhiman committed Apr 4, 2019
1 parent cc765cc commit b6c9117
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
12 changes: 9 additions & 3 deletions types/lib/query-interface.d.ts
Expand Up @@ -5,6 +5,8 @@ import QueryTypes = require('./query-types');
import { Sequelize, RetryOptions } from './sequelize';
import { Transaction } from './transaction';

type BindOrReplacements = { [key: string]: unknown } | unknown[];

/**
* Interface for query options
*/
Expand Down Expand Up @@ -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
* replacements to replace `?` in your SQL.
*/
replacements?: {
[key: string]: string | number | string[] | number[];
} | string[];
replacements?: BindOrReplacements;

/**
* 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.
Expand Down
10 changes: 9 additions & 1 deletion types/test/connection.ts
Expand Up @@ -35,4 +35,12 @@ sequelize.transaction<void>(async transaction => {
transaction,
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 }
);

0 comments on commit b6c9117

Please sign in to comment.