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

Commit b3d28490 by Erik Seliger Committed by GitHub

fix(types): add poolable to count options (#10938)

1 parent e7c86283
...@@ -34,6 +34,15 @@ export interface Logging { ...@@ -34,6 +34,15 @@ export interface Logging {
benchmark?: boolean; benchmark?: boolean;
} }
export interface Poolable {
/**
* Force the query to use the write pool, regardless of the query type.
*
* @default false
*/
useMaster?: boolean;
}
export interface Transactionable { export interface Transactionable {
/** /**
* Transaction to run query under * Transaction to run query under
...@@ -551,7 +560,7 @@ export interface NonNullFindOptions extends FindOptions { ...@@ -551,7 +560,7 @@ export interface NonNullFindOptions extends FindOptions {
/** /**
* Options for Model.count method * Options for Model.count method
*/ */
export interface CountOptions extends Logging, Transactionable, Filterable, Projectable, Paranoid { export interface CountOptions extends Logging, Transactionable, Filterable, Projectable, Paranoid, Poolable {
/** /**
* Include options. See `find` for details * Include options. See `find` for details
*/ */
......
import { DataType } from './data-types'; import { DataType } from './data-types';
import { Logging, Model, ModelAttributeColumnOptions, ModelAttributes, Transactionable, WhereOptions, Filterable } from './model'; import { Logging, Model, ModelAttributeColumnOptions, ModelAttributes, Transactionable, WhereOptions, Filterable, Poolable } from './model';
import { Promise } from './promise'; import { Promise } from './promise';
import QueryTypes = require('./query-types'); import QueryTypes = require('./query-types');
import { Sequelize, RetryOptions } from './sequelize'; import { Sequelize, RetryOptions } from './sequelize';
...@@ -10,7 +10,7 @@ type BindOrReplacements = { [key: string]: unknown } | unknown[]; ...@@ -10,7 +10,7 @@ type BindOrReplacements = { [key: string]: unknown } | unknown[];
/** /**
* Interface for query options * Interface for query options
*/ */
export interface QueryOptions extends Logging, Transactionable { export interface QueryOptions extends Logging, Transactionable, Poolable {
/** /**
* If true, sequelize will not try to format the results of the query, or build an instance of a model from * If true, sequelize will not try to format the results of the query, or build an instance of a model from
* the result * the result
...@@ -51,13 +51,6 @@ export interface QueryOptions extends Logging, Transactionable { ...@@ -51,13 +51,6 @@ export interface QueryOptions extends Logging, Transactionable {
bind?: BindOrReplacements; bind?: BindOrReplacements;
/** /**
* Force the query to use the write pool, regardless of the query type.
*
* @default false
*/
useMaster?: boolean;
/**
* A sequelize instance used to build the return instance * A sequelize instance used to build the return instance
*/ */
instance?: Model; instance?: Model;
......
import { Model, Promise } from 'sequelize'; import { Model, Promise, Op } from 'sequelize';
class MyModel extends Model {} class MyModel extends Model {}
const grouped: Promise<{ [key: string]: number }> = MyModel.count({ group: 'tag' }); const grouped: Promise<{ [key: string]: number }> = MyModel.count({ group: 'tag' });
const counted: Promise<number> = MyModel.count(); const counted: Promise<number> = MyModel.count();
const countedDistinct: Promise<number> = MyModel.count({ col: 'tag', distinct: true }); const countedDistinct: Promise<number> = MyModel.count({ col: 'tag', distinct: true });
\ No newline at end of file
const countedDistinctOnReader: Promise<number> = MyModel.count({ where: { updatedAt: { [Op.gte]: new Date() } }, useMaster: false })
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!