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

Commit 1d3714a2 by Simon Schick Committed by Sushant

chore: misc cleanup (#10483)

1 parent 24291467
...@@ -235,7 +235,7 @@ const sequelize = new Sequelize('database', 'username', 'password', { ...@@ -235,7 +235,7 @@ const sequelize = new Sequelize('database', 'username', 'password', {
### MSSQL ### MSSQL
The library for MSSQL is`tedious@^1.7.0` You'll just need to define the dialect: The library for MSSQL is`tedious@^3.0.0` You'll just need to define the dialect:
```js ```js
const sequelize = new Sequelize('database', 'username', 'password', { const sequelize = new Sequelize('database', 'username', 'password', {
......
...@@ -132,6 +132,10 @@ class Association { ...@@ -132,6 +132,10 @@ class Association {
}); });
} }
[Symbol.for('nodejs.util.inspect.custom')]() {
return this.as;
}
inspect() { inspect() {
return this.as; return this.as;
} }
......
...@@ -96,7 +96,7 @@ module.exports = BaseTypes => { ...@@ -96,7 +96,7 @@ module.exports = BaseTypes => {
if (!(this instanceof DATEONLY)) { if (!(this instanceof DATEONLY)) {
return new DATEONLY(); return new DATEONLY();
} }
BaseTypes.DATEONLY.apply(this, arguments); BaseTypes.DATEONLY.call(this);
} }
inherits(DATEONLY, BaseTypes.DATEONLY); inherits(DATEONLY, BaseTypes.DATEONLY);
...@@ -109,7 +109,7 @@ module.exports = BaseTypes => { ...@@ -109,7 +109,7 @@ module.exports = BaseTypes => {
if (!(this instanceof UUID)) { if (!(this instanceof UUID)) {
return new UUID(); return new UUID();
} }
BaseTypes.UUID.apply(this, arguments); BaseTypes.UUID.call(this);
} }
inherits(UUID, BaseTypes.UUID); inherits(UUID, BaseTypes.UUID);
...@@ -156,7 +156,7 @@ module.exports = BaseTypes => { ...@@ -156,7 +156,7 @@ module.exports = BaseTypes => {
if (!(this instanceof JSONTYPE)) { if (!(this instanceof JSONTYPE)) {
return new JSONTYPE(); return new JSONTYPE();
} }
BaseTypes.JSON.apply(this, arguments); BaseTypes.JSON.call(this);
} }
inherits(JSONTYPE, BaseTypes.JSON); inherits(JSONTYPE, BaseTypes.JSON);
......
...@@ -116,7 +116,7 @@ module.exports = BaseTypes => { ...@@ -116,7 +116,7 @@ module.exports = BaseTypes => {
function BOOLEAN() { function BOOLEAN() {
if (!(this instanceof BOOLEAN)) return new BOOLEAN(); if (!(this instanceof BOOLEAN)) return new BOOLEAN();
BaseTypes.BOOLEAN.apply(this, arguments); BaseTypes.BOOLEAN.call(this);
} }
inherits(BOOLEAN, BaseTypes.BOOLEAN); inherits(BOOLEAN, BaseTypes.BOOLEAN);
...@@ -126,7 +126,7 @@ module.exports = BaseTypes => { ...@@ -126,7 +126,7 @@ module.exports = BaseTypes => {
function UUID() { function UUID() {
if (!(this instanceof UUID)) return new UUID(); if (!(this instanceof UUID)) return new UUID();
BaseTypes.UUID.apply(this, arguments); BaseTypes.UUID.call(this);
} }
inherits(UUID, BaseTypes.UUID); inherits(UUID, BaseTypes.UUID);
...@@ -136,7 +136,7 @@ module.exports = BaseTypes => { ...@@ -136,7 +136,7 @@ module.exports = BaseTypes => {
function NOW() { function NOW() {
if (!(this instanceof NOW)) return new NOW(); if (!(this instanceof NOW)) return new NOW();
BaseTypes.NOW.apply(this, arguments); BaseTypes.NOW.call(this);
} }
inherits(NOW, BaseTypes.NOW); inherits(NOW, BaseTypes.NOW);
...@@ -156,7 +156,7 @@ module.exports = BaseTypes => { ...@@ -156,7 +156,7 @@ module.exports = BaseTypes => {
function DATEONLY() { function DATEONLY() {
if (!(this instanceof DATEONLY)) return new DATEONLY(); if (!(this instanceof DATEONLY)) return new DATEONLY();
BaseTypes.DATEONLY.apply(this, arguments); BaseTypes.DATEONLY.call(this);
} }
inherits(DATEONLY, BaseTypes.DATEONLY); inherits(DATEONLY, BaseTypes.DATEONLY);
......
...@@ -94,7 +94,7 @@ module.exports = BaseTypes => { ...@@ -94,7 +94,7 @@ module.exports = BaseTypes => {
function DATEONLY() { function DATEONLY() {
if (!(this instanceof DATEONLY)) return new DATEONLY(); if (!(this instanceof DATEONLY)) return new DATEONLY();
BaseTypes.DATEONLY.apply(this, arguments); BaseTypes.DATEONLY.call(this);
} }
inherits(DATEONLY, BaseTypes.DATEONLY); inherits(DATEONLY, BaseTypes.DATEONLY);
...@@ -104,7 +104,7 @@ module.exports = BaseTypes => { ...@@ -104,7 +104,7 @@ module.exports = BaseTypes => {
function UUID() { function UUID() {
if (!(this instanceof UUID)) return new UUID(); if (!(this instanceof UUID)) return new UUID();
BaseTypes.UUID.apply(this, arguments); BaseTypes.UUID.call(this);
} }
inherits(UUID, BaseTypes.UUID); inherits(UUID, BaseTypes.UUID);
...@@ -164,7 +164,7 @@ module.exports = BaseTypes => { ...@@ -164,7 +164,7 @@ module.exports = BaseTypes => {
function JSONTYPE() { function JSONTYPE() {
if (!(this instanceof JSONTYPE)) return new JSONTYPE(); if (!(this instanceof JSONTYPE)) return new JSONTYPE();
BaseTypes.JSON.apply(this, arguments); BaseTypes.JSON.call(this);
} }
inherits(JSONTYPE, BaseTypes.JSON); inherits(JSONTYPE, BaseTypes.JSON);
......
...@@ -41,7 +41,7 @@ module.exports = BaseTypes => { ...@@ -41,7 +41,7 @@ module.exports = BaseTypes => {
function DATEONLY() { function DATEONLY() {
if (!(this instanceof DATEONLY)) return new DATEONLY(); if (!(this instanceof DATEONLY)) return new DATEONLY();
BaseTypes.DATEONLY.apply(this, arguments); BaseTypes.DATEONLY.call(this);
} }
inherits(DATEONLY, BaseTypes.DATEONLY); inherits(DATEONLY, BaseTypes.DATEONLY);
...@@ -134,7 +134,7 @@ module.exports = BaseTypes => { ...@@ -134,7 +134,7 @@ module.exports = BaseTypes => {
function CITEXT() { function CITEXT() {
if (!(this instanceof CITEXT)) return new CITEXT(); if (!(this instanceof CITEXT)) return new CITEXT();
BaseTypes.CITEXT.apply(this, arguments); BaseTypes.CITEXT.call(this);
} }
inherits(CITEXT, BaseTypes.CITEXT); inherits(CITEXT, BaseTypes.CITEXT);
...@@ -159,7 +159,7 @@ module.exports = BaseTypes => { ...@@ -159,7 +159,7 @@ module.exports = BaseTypes => {
function BOOLEAN() { function BOOLEAN() {
if (!(this instanceof BOOLEAN)) return new BOOLEAN(); if (!(this instanceof BOOLEAN)) return new BOOLEAN();
BaseTypes.BOOLEAN.apply(this, arguments); BaseTypes.BOOLEAN.call(this);
} }
inherits(BOOLEAN, BaseTypes.BOOLEAN); inherits(BOOLEAN, BaseTypes.BOOLEAN);
......
...@@ -47,7 +47,7 @@ module.exports = BaseTypes => { ...@@ -47,7 +47,7 @@ module.exports = BaseTypes => {
function JSONTYPE() { function JSONTYPE() {
if (!(this instanceof JSONTYPE)) return new JSONTYPE(); if (!(this instanceof JSONTYPE)) return new JSONTYPE();
BaseTypes.JSON.apply(this, arguments); BaseTypes.JSON.call(this);
} }
inherits(JSONTYPE, BaseTypes.JSON); inherits(JSONTYPE, BaseTypes.JSON);
...@@ -71,7 +71,7 @@ module.exports = BaseTypes => { ...@@ -71,7 +71,7 @@ module.exports = BaseTypes => {
function DATEONLY() { function DATEONLY() {
if (!(this instanceof DATEONLY)) return new DATEONLY(); if (!(this instanceof DATEONLY)) return new DATEONLY();
BaseTypes.DATEONLY.apply(this, arguments); BaseTypes.DATEONLY.call(this);
} }
inherits(DATEONLY, BaseTypes.DATEONLY); inherits(DATEONLY, BaseTypes.DATEONLY);
...@@ -108,7 +108,7 @@ module.exports = BaseTypes => { ...@@ -108,7 +108,7 @@ module.exports = BaseTypes => {
function CITEXT() { function CITEXT() {
if (!(this instanceof CITEXT)) return new CITEXT(); if (!(this instanceof CITEXT)) return new CITEXT();
BaseTypes.CITEXT.apply(this, arguments); BaseTypes.CITEXT.call(this);
} }
inherits(CITEXT, BaseTypes.CITEXT); inherits(CITEXT, BaseTypes.CITEXT);
......
...@@ -27,9 +27,7 @@ class ModelManager { ...@@ -27,9 +27,7 @@ class ModelManager {
attribute: 'name' attribute: 'name'
}); });
const model = this.models.filter(model => model[options.attribute] === against); return this.models.find(model => model[options.attribute] === against);
return model ? model[0] : null;
} }
get all() { get all() {
......
...@@ -3068,6 +3068,10 @@ class Model { ...@@ -3068,6 +3068,10 @@ class Model {
this._defaultsOptions(options, scope); this._defaultsOptions(options, scope);
} }
static [Symbol.for('nodejs.util.inspect.custom')]() {
return this.name;
}
static inspect() { static inspect() {
return this.name; return this.name;
} }
......
...@@ -50,9 +50,9 @@ ...@@ -50,9 +50,9 @@
"devDependencies": { "devDependencies": {
"@commitlint/cli": "^7.3.2", "@commitlint/cli": "^7.3.2",
"@commitlint/config-angular": "^7.3.1", "@commitlint/config-angular": "^7.3.1",
"@types/bluebird": "^3.5.25", "@types/bluebird": "^3.5.26",
"@types/node": "^10.12.18", "@types/node": "^10.12.27",
"@types/validator": "^9.4.4", "@types/validator": "^10.9.0",
"chai": "^4.x", "chai": "^4.x",
"chai-as-promised": "^7.x", "chai-as-promised": "^7.x",
"chai-datetime": "^1.x", "chai-datetime": "^1.x",
...@@ -72,18 +72,18 @@ ...@@ -72,18 +72,18 @@
"lcov-result-merger": "^3.0.0", "lcov-result-merger": "^3.0.0",
"lint-staged": "^8.1.0", "lint-staged": "^8.1.0",
"mariadb": "^2.0.3", "mariadb": "^2.0.3",
"mocha": "^5.x", "mocha": "^6.0.2",
"mysql2": "^1.6.4", "mysql2": "^1.6.5",
"nyc": "^13.3.0", "nyc": "^13.3.0",
"pg": "^7.8.0", "pg": "^7.8.0",
"pg-hstore": "^2.x", "pg-hstore": "^2.x",
"pg-types": "^2.0.0", "pg-types": "^2.0.0",
"rimraf": "^2.x", "rimraf": "^2.6.3",
"sinon": "^6.3.5", "sinon": "^7.2.4",
"sinon-chai": "^3.2.0", "sinon-chai": "^3.2.0",
"sqlite3": "^4.0.6", "sqlite3": "^4.0.6",
"tedious": "^3.0.1", "tedious": "^3.0.1",
"typescript": "^3.2.2" "typescript": "^3.3.3333"
}, },
"keywords": [ "keywords": [
"mysql", "mysql",
...@@ -121,7 +121,7 @@ ...@@ -121,7 +121,7 @@
"test-docker-integration": "env-cmd $npm_package_options_env_cmd npm run test-integration", "test-docker-integration": "env-cmd $npm_package_options_env_cmd npm run test-integration",
"docs": "esdoc && cp docs/ROUTER esdoc/ROUTER && cp docs/favicon.ico esdoc/favicon.ico", "docs": "esdoc && cp docs/ROUTER esdoc/ROUTER && cp docs/favicon.ico esdoc/favicon.ico",
"teaser": "node scripts/teaser", "teaser": "node scripts/teaser",
"test-unit": "mocha --require scripts/mocha-bootload --globals setImmediate,clearImmediate --ui tdd --exit --check-leaks --colors -t 30000 --reporter spec \"test/unit/**/*.js\"", "test-unit": "mocha --require scripts/mocha-bootload --globals setImmediate,clearImmediate --exit --check-leaks --colors -t 30000 --reporter spec \"test/unit/**/*.js\"",
"test-unit-mariadb": "cross-env DIALECT=mariadb npm run test-unit", "test-unit-mariadb": "cross-env DIALECT=mariadb npm run test-unit",
"test-unit-mysql": "cross-env DIALECT=mysql npm run test-unit", "test-unit-mysql": "cross-env DIALECT=mysql npm run test-unit",
"test-unit-postgres": "cross-env DIALECT=postgres npm run test-unit", "test-unit-postgres": "cross-env DIALECT=postgres npm run test-unit",
...@@ -129,7 +129,7 @@ ...@@ -129,7 +129,7 @@
"test-unit-sqlite": "cross-env DIALECT=sqlite npm run test-unit", "test-unit-sqlite": "cross-env DIALECT=sqlite npm run test-unit",
"test-unit-mssql": "cross-env DIALECT=mssql npm run test-unit", "test-unit-mssql": "cross-env DIALECT=mssql npm run test-unit",
"test-unit-all": "npm run test-unit-mariadb && npm run test-unit-mysql && npm run test-unit-postgres && npm run test-unit-postgres-native && npm run test-unit-mssql && npm run test-unit-sqlite", "test-unit-all": "npm run test-unit-mariadb && npm run test-unit-mysql && npm run test-unit-postgres && npm run test-unit-postgres-native && npm run test-unit-mssql && npm run test-unit-sqlite",
"test-integration": "mocha --require scripts/mocha-bootload --globals setImmediate,clearImmediate --ui tdd --exit --check-leaks --colors -t 30000 --reporter spec \"test/integration/**/*.test.js\"", "test-integration": "mocha --require scripts/mocha-bootload --globals setImmediate,clearImmediate --exit --check-leaks --colors -t 30000 --reporter spec \"test/integration/**/*.test.js\"",
"test-integration-mariadb": "cross-env DIALECT=mariadb npm run test-integration", "test-integration-mariadb": "cross-env DIALECT=mariadb npm run test-integration",
"test-integration-mysql": "cross-env DIALECT=mysql npm run test-integration", "test-integration-mysql": "cross-env DIALECT=mysql npm run test-integration",
"test-integration-postgres": "cross-env DIALECT=postgres npm run test-integration", "test-integration-postgres": "cross-env DIALECT=postgres npm run test-integration",
...@@ -148,8 +148,8 @@ ...@@ -148,8 +148,8 @@
"test-all": "npm run test-mariadb && npm run test-mysql && npm run test-sqlite && npm run test-postgres && npm run test-postgres-native && npm run test-mssql", "test-all": "npm run test-mariadb && npm run test-mysql && npm run test-sqlite && npm run test-postgres && npm run test-postgres-native && npm run test-mssql",
"test-typings": "tsc -b types/tsconfig.json && tsc -b types/test/tsconfig.json", "test-typings": "tsc -b types/tsconfig.json && tsc -b types/test/tsconfig.json",
"cover": "rimraf coverage && npm run teaser && npm run cover-integration && npm run cover-unit && npm run merge-coverage", "cover": "rimraf coverage && npm run teaser && npm run cover-integration && npm run cover-unit && npm run merge-coverage",
"cover-integration": "cross-env COVERAGE=true nyc --reporter=lcovonly mocha --require scripts/mocha-bootload -t 30000 --exit --ui tdd \"test/integration/**/*.test.js\" && node -e \"require('fs').renameSync('coverage/lcov.info', 'coverage/integration.info')\"", "cover-integration": "cross-env COVERAGE=true nyc --reporter=lcovonly mocha --require scripts/mocha-bootload -t 30000 --exit \"test/integration/**/*.test.js\" && node -e \"require('fs').renameSync('coverage/lcov.info', 'coverage/integration.info')\"",
"cover-unit": "cross-env COVERAGE=true nyc --reporter=lcovonly mocha --require scripts/mocha-bootload -t 30000 --exit --ui tdd \"test/unit/**/*.test.js\" && node -e \"require('fs').renameSync('coverage/lcov.info', 'coverage/unit.info')\"", "cover-unit": "cross-env COVERAGE=true nyc --reporter=lcovonly mocha --require scripts/mocha-bootload -t 30000 --exit \"test/unit/**/*.test.js\" && node -e \"require('fs').renameSync('coverage/lcov.info', 'coverage/unit.info')\"",
"merge-coverage": "lcov-result-merger \"coverage/*.info\" \"coverage/lcov.info\"", "merge-coverage": "lcov-result-merger \"coverage/*.info\" \"coverage/lcov.info\"",
"sscce": "env-cmd $npm_package_options_env_cmd node sscce.js", "sscce": "env-cmd $npm_package_options_env_cmd node sscce.js",
"sscce-mariadb": "cross-env DIALECT=mariadb npm run sscce", "sscce-mariadb": "cross-env DIALECT=mariadb npm run sscce",
......
...@@ -101,7 +101,7 @@ export interface AssociationScope { ...@@ -101,7 +101,7 @@ export interface AssociationScope {
/** /**
* The name of the column that will be used for the associated scope and it's value * The name of the column that will be used for the associated scope and it's value
*/ */
[scopeName: string]: any; [scopeName: string]: unknown;
} }
/** /**
......
...@@ -41,7 +41,7 @@ export interface ThroughOptions { ...@@ -41,7 +41,7 @@ export interface ThroughOptions {
* Attributes for the join table * Attributes for the join table
*/ */
export interface JoinTableAttributes { export interface JoinTableAttributes {
[attribute: string]: any; [attribute: string]: unknown;
} }
/** /**
...@@ -273,7 +273,7 @@ export interface BelongsToManyCreateAssociationMixinOptions extends CreateOption ...@@ -273,7 +273,7 @@ export interface BelongsToManyCreateAssociationMixinOptions extends CreateOption
* @see Instance * @see Instance
*/ */
export type BelongsToManyCreateAssociationMixin<TModel> = ( export type BelongsToManyCreateAssociationMixin<TModel> = (
values?: { [attribute: string]: any }, values?: { [attribute: string]: unknown },
options?: BelongsToManyCreateAssociationMixinOptions options?: BelongsToManyCreateAssociationMixinOptions
) => Promise<TModel>; ) => Promise<TModel>;
......
...@@ -116,7 +116,7 @@ export interface BelongsToCreateAssociationMixinOptions extends CreateOptions, B ...@@ -116,7 +116,7 @@ export interface BelongsToCreateAssociationMixinOptions extends CreateOptions, B
* @see Instance * @see Instance
*/ */
export type BelongsToCreateAssociationMixin<TModel> = ( export type BelongsToCreateAssociationMixin<TModel> = (
values?: { [attribute: string]: any }, values?: { [attribute: string]: unknown },
options?: BelongsToCreateAssociationMixinOptions options?: BelongsToCreateAssociationMixinOptions
) => Promise<TModel>; ) => Promise<TModel>;
......
...@@ -205,7 +205,7 @@ export interface HasManyCreateAssociationMixinOptions extends CreateOptions {} ...@@ -205,7 +205,7 @@ export interface HasManyCreateAssociationMixinOptions extends CreateOptions {}
* @see Instance * @see Instance
*/ */
export type HasManyCreateAssociationMixin<TModel> = ( export type HasManyCreateAssociationMixin<TModel> = (
values?: { [attribute: string]: any }, values?: { [attribute: string]: unknown },
options?: HasManyCreateAssociationMixinOptions options?: HasManyCreateAssociationMixinOptions
) => Promise<TModel>; ) => Promise<TModel>;
......
...@@ -108,6 +108,6 @@ export interface HasOneCreateAssociationMixinOptions extends HasOneSetAssociatio ...@@ -108,6 +108,6 @@ export interface HasOneCreateAssociationMixinOptions extends HasOneSetAssociatio
* @see Instance * @see Instance
*/ */
export type HasOneCreateAssociationMixin<TModel> = ( export type HasOneCreateAssociationMixin<TModel> = (
values?: { [attribute: string]: any }, values?: { [attribute: string]: unknown },
options?: HasOneCreateAssociationMixinOptions options?: HasOneCreateAssociationMixinOptions
) => Promise<TModel>; ) => Promise<TModel>;
...@@ -78,7 +78,7 @@ interface StringDataTypeConstructor extends AbstractDataTypeConstructor { ...@@ -78,7 +78,7 @@ interface StringDataTypeConstructor extends AbstractDataTypeConstructor {
export interface StringDataType extends AbstractDataType { export interface StringDataType extends AbstractDataType {
options?: StringDataTypeOptions; options?: StringDataTypeOptions;
BINARY: this; BINARY: this;
validate(value: any): boolean; validate(value: unknown): boolean;
} }
export interface StringDataTypeOptions { export interface StringDataTypeOptions {
...@@ -119,7 +119,7 @@ interface TextDataTypeConstructor extends AbstractDataTypeConstructor { ...@@ -119,7 +119,7 @@ interface TextDataTypeConstructor extends AbstractDataTypeConstructor {
export interface TextDataType extends AbstractDataType { export interface TextDataType extends AbstractDataType {
options: TextDataTypeOptions; options: TextDataTypeOptions;
validate(value: any): boolean; validate(value: unknown): boolean;
} }
export interface TextDataTypeOptions { export interface TextDataTypeOptions {
...@@ -134,14 +134,14 @@ interface NumberDataTypeConstructor extends AbstractDataTypeConstructor { ...@@ -134,14 +134,14 @@ interface NumberDataTypeConstructor extends AbstractDataTypeConstructor {
ZEROFILL: this; ZEROFILL: this;
new (options?: NumberDataTypeOptions): NumberDataType; new (options?: NumberDataTypeOptions): NumberDataType;
(options?: NumberDataTypeOptions): NumberDataType; (options?: NumberDataTypeOptions): NumberDataType;
validate(value: any): boolean; validate(value: unknown): boolean;
} }
export interface NumberDataType extends AbstractDataType { export interface NumberDataType extends AbstractDataType {
options: NumberDataTypeOptions; options: NumberDataTypeOptions;
UNSIGNED: this; UNSIGNED: this;
ZEROFILL: this; ZEROFILL: this;
validate(value: any): boolean; validate(value: unknown): boolean;
} }
export interface NumberDataTypeOptions { export interface NumberDataTypeOptions {
...@@ -297,9 +297,9 @@ export const TIME: AbstractDataTypeConstructor; ...@@ -297,9 +297,9 @@ export const TIME: AbstractDataTypeConstructor;
export const DATE: DateDataTypeConstructor; export const DATE: DateDataTypeConstructor;
interface DateDataTypeConstructor extends AbstractDataTypeConstructor { interface DateDataTypeConstructor extends AbstractDataTypeConstructor {
new (length?: any): DateDataType; new (length?: string | number): DateDataType;
new (options?: DateDataTypeOptions): DateDataType; new (options?: DateDataTypeOptions): DateDataType;
(length?: any): DateDataType; (length?: string | number): DateDataType;
(options?: DateDataTypeOptions): DateDataType; (options?: DateDataTypeOptions): DateDataType;
} }
...@@ -308,7 +308,7 @@ export interface DateDataType extends AbstractDataTypeConstructor { ...@@ -308,7 +308,7 @@ export interface DateDataType extends AbstractDataTypeConstructor {
} }
export interface DateDataTypeOptions { export interface DateDataTypeOptions {
length?: any; length?: string | number;
} }
/** /**
...@@ -317,19 +317,13 @@ export interface DateDataTypeOptions { ...@@ -317,19 +317,13 @@ export interface DateDataTypeOptions {
export const DATEONLY: DateOnlyDataTypeConstructor; export const DATEONLY: DateOnlyDataTypeConstructor;
interface DateOnlyDataTypeConstructor extends AbstractDataTypeConstructor { interface DateOnlyDataTypeConstructor extends AbstractDataTypeConstructor {
new (length: any): DateOnlyDataType; new (): DateOnlyDataType;
new (options: DateOnlyDataTypeOptions): DateOnlyDataType; (): DateOnlyDataType;
(length: any): DateOnlyDataType;
(options: DateOnlyDataTypeOptions): DateOnlyDataType;
} }
export interface DateOnlyDataType extends AbstractDataType { export interface DateOnlyDataType extends AbstractDataType {
options: DateOnlyDataTypeOptions;
} }
export interface DateOnlyDataTypeOptions {
length?: any;
}
/** /**
* A key / value column. Only available in postgres. * A key / value column. Only available in postgres.
...@@ -510,7 +504,7 @@ interface ArrayDataTypeConstructor extends AbstractDataTypeConstructor { ...@@ -510,7 +504,7 @@ interface ArrayDataTypeConstructor extends AbstractDataTypeConstructor {
new <T extends AbstractDataTypeConstructor | AbstractDataType>(options: ArrayDataTypeOptions<T>): ArrayDataType<T>; new <T extends AbstractDataTypeConstructor | AbstractDataType>(options: ArrayDataTypeOptions<T>): ArrayDataType<T>;
<T extends AbstractDataTypeConstructor | AbstractDataType>(type: T): ArrayDataType<T>; <T extends AbstractDataTypeConstructor | AbstractDataType>(type: T): ArrayDataType<T>;
<T extends AbstractDataTypeConstructor | AbstractDataType>(options: ArrayDataTypeOptions<T>): ArrayDataType<T>; <T extends AbstractDataTypeConstructor | AbstractDataType>(options: ArrayDataTypeOptions<T>): ArrayDataType<T>;
is<T extends AbstractDataTypeConstructor | AbstractDataType>(obj: any, type: T): obj is ArrayDataType<T>; is<T extends AbstractDataTypeConstructor | AbstractDataType>(obj: unknown, type: T): obj is ArrayDataType<T>;
} }
export interface ArrayDataType<T extends AbstractDataTypeConstructor | AbstractDataType> extends AbstractDataType { export interface ArrayDataType<T extends AbstractDataTypeConstructor | AbstractDataType> extends AbstractDataType {
......
...@@ -93,7 +93,7 @@ export interface UniqueConstraintErrorOptions { ...@@ -93,7 +93,7 @@ export interface UniqueConstraintErrorOptions {
parent?: Error; parent?: Error;
message?: string; message?: string;
errors?: ValidationErrorItem[]; errors?: ValidationErrorItem[];
fields?: { [key: string]: any }; fields?: { [key: string]: unknown };
original?: Error; original?: Error;
} }
...@@ -104,7 +104,7 @@ export class UniqueConstraintError extends ValidationError implements CommonErro ...@@ -104,7 +104,7 @@ export class UniqueConstraintError extends ValidationError implements CommonErro
public readonly parent: Error; public readonly parent: Error;
public readonly original: Error; public readonly original: Error;
public readonly sql: string; public readonly sql: string;
public readonly fields: { [key: string]: any }; public readonly fields: { [key: string]: unknown };
constructor(options?: UniqueConstraintErrorOptions); constructor(options?: UniqueConstraintErrorOptions);
} }
...@@ -114,7 +114,7 @@ export class UniqueConstraintError extends ValidationError implements CommonErro ...@@ -114,7 +114,7 @@ export class UniqueConstraintError extends ValidationError implements CommonErro
export class ForeignKeyConstraintError extends DatabaseError { export class ForeignKeyConstraintError extends DatabaseError {
public table: string; public table: string;
public fields: { [field: string]: string }; public fields: { [field: string]: string };
public value: any; public value: unknown;
public index: string; public index: string;
constructor(options: { parent?: Error; message?: string; index?: string; fields?: string[]; table?: string }); constructor(options: { parent?: Error; message?: string; index?: string; fields?: string[]; table?: string });
} }
......
...@@ -54,7 +54,7 @@ export interface AllModelHooks extends ModelHookOptions { ...@@ -54,7 +54,7 @@ export interface AllModelHooks extends ModelHookOptions {
export interface SequelizeHooks extends AllModelHooks { export interface SequelizeHooks extends AllModelHooks {
beforeConnect(config: Config): HookReturn; beforeConnect(config: Config): HookReturn;
afterConnect(connection: any, config: Config): HookReturn; afterConnect(connection: unknown, config: Config): HookReturn;
} }
/** /**
......
...@@ -9,7 +9,7 @@ export class ModelManager { ...@@ -9,7 +9,7 @@ export class ModelManager {
constructor(sequelize: Sequelize); constructor(sequelize: Sequelize);
public addModel<T extends typeof Model>(model: T): T; public addModel<T extends typeof Model>(model: T): T;
public removeModel(model: typeof Model): void; public removeModel(model: typeof Model): void;
public getModel(against: any, options?: { attribute?: string }): typeof Model; public getModel(against: unknown, options?: { attribute?: string }): typeof Model;
} }
export default ModelManager; export default ModelManager;
...@@ -105,7 +105,7 @@ export interface ScopeOptions { ...@@ -105,7 +105,7 @@ export interface ScopeOptions {
* any arguments, or an array, where the first element is the name of the method, and consecutive elements * any arguments, or an array, where the first element is the name of the method, and consecutive elements
* are arguments to that method. Pass null to remove all scopes, including the default. * are arguments to that method. Pass null to remove all scopes, including the default.
*/ */
method: string | any[]; method: string | [string, ...unknown[]];
} }
/** /**
...@@ -199,14 +199,14 @@ export interface WhereOperators { ...@@ -199,14 +199,14 @@ export interface WhereOperators {
* *
* Example: `[Op.contains]: [1, 2]` becomes `@> [1, 2]` * Example: `[Op.contains]: [1, 2]` becomes `@> [1, 2]`
*/ */
[Op.contains]?: any[]; [Op.contains]?: [number, number] | [Date, Date];
/** /**
* PG array contained by operator * PG array contained by operator
* *
* Example: `[Op.contained]: [1, 2]` becomes `<@ [1, 2]` * Example: `[Op.contained]: [1, 2]` becomes `<@ [1, 2]`
*/ */
[Op.contained]?: any[]; [Op.contained]?: [number, number] | [Date, Date];
/** Example: `[Op.gt]: 6,` becomes `> 6` */ /** Example: `[Op.gt]: 6,` becomes `> 6` */
[Op.gt]?: number | string | Date; [Op.gt]?: number | string | Date;
...@@ -322,6 +322,11 @@ export interface IncludeOptions extends Filterable, Projectable { ...@@ -322,6 +322,11 @@ export interface IncludeOptions extends Filterable, Projectable {
association?: Association; association?: Association;
/** /**
* Custom `on` clause, overrides default.
*/
on?: WhereOptions;
/**
* Note that this converts the eager load to an inner join, * Note that this converts the eager load to an inner join,
* unless you explicitly set `required: false` * unless you explicitly set `required: false`
*/ */
...@@ -997,14 +1002,14 @@ export interface ModelValidateOptions { ...@@ -997,14 +1002,14 @@ export interface ModelValidateOptions {
* We can't enforce any other method to be a function, so : * We can't enforce any other method to be a function, so :
* *
* ```typescript * ```typescript
* [name: string] : ( value : any ) => boolean; * [name: string] : ( value : unknown ) => boolean;
* ``` * ```
* *
* doesn't work in combination with the properties above * doesn't work in combination with the properties above
* *
* @see https://github.com/Microsoft/TypeScript/issues/1889 * @see https://github.com/Microsoft/TypeScript/issues/1889
*/ */
[name: string]: any; [name: string]: unknown;
} }
/** /**
...@@ -1069,14 +1074,14 @@ export interface ModelNameOptions { ...@@ -1069,14 +1074,14 @@ export interface ModelNameOptions {
* Interface for getterMethods in DefineOptions * Interface for getterMethods in DefineOptions
*/ */
export interface ModelGetterOptions { export interface ModelGetterOptions {
[name: string]: () => any; [name: string]: (this: Model) => unknown;
} }
/** /**
* Interface for setterMethods in DefineOptions * Interface for setterMethods in DefineOptions
*/ */
export interface ModelSetterOptions { export interface ModelSetterOptions {
[name: string]: (val: any) => void; [name: string]: (this: Model, val: any) => void;
} }
/** /**
...@@ -1107,7 +1112,7 @@ export interface ColumnOptions { ...@@ -1107,7 +1112,7 @@ export interface ColumnOptions {
/** /**
* A literal default value, a JavaScript function, or an SQL function (see `sequelize.fn`) * A literal default value, a JavaScript function, or an SQL function (see `sequelize.fn`)
*/ */
defaultValue?: any; defaultValue?: unknown;
} }
/** /**
...@@ -1210,13 +1215,13 @@ export interface ModelAttributeColumnOptions extends ColumnOptions { ...@@ -1210,13 +1215,13 @@ export interface ModelAttributeColumnOptions extends ColumnOptions {
* Provide a custom getter for this column. Use `this.getDataValue(String)` to manipulate the underlying * Provide a custom getter for this column. Use `this.getDataValue(String)` to manipulate the underlying
* values. * values.
*/ */
get?(): any; get?(): unknown;
/** /**
* Provide a custom setter for this column. Use `this.setDataValue(String, Value)` to manipulate the * Provide a custom setter for this column. Use `this.setDataValue(String, Value)` to manipulate the
* underlying values. * underlying values.
*/ */
set?(val: any): void; set?(val: unknown): void;
} }
/** /**
...@@ -1351,6 +1356,16 @@ export interface ModelOptions<M extends Model = Model> { ...@@ -1351,6 +1356,16 @@ export interface ModelOptions<M extends Model = Model> {
* accepts an optional error. * accepts an optional error.
*/ */
validate?: ModelValidateOptions; validate?: ModelValidateOptions;
/**
* Allows defining additional setters that will be available on model instances.
*/
setterMethods?: ModelSetterOptions;
/**
* Allows defining additional getters that will be available on model instances.
*/
getterMethods?: ModelGetterOptions;
} }
/** /**
...@@ -1375,32 +1390,39 @@ export interface AddScopeOptions { ...@@ -1375,32 +1390,39 @@ export interface AddScopeOptions {
export abstract class Model<T = any, T2 = any> extends Hooks { export abstract class Model<T = any, T2 = any> extends Hooks {
/** The name of the database table */ /** The name of the database table */
public static tableName: string; public static readonly tableName: string;
/** /**
* The name of the primary key attribute * The name of the primary key attribute
*/ */
public static primaryKeyAttribute: string; public static readonly primaryKeyAttribute: string;
/** /**
* An object hash from alias to association object * An object hash from alias to association object
*/ */
public static associations: any; public static readonly associations: {
[key: string]: Association;
};
/** /**
* The options that the model was initialized with * The options that the model was initialized with
*/ */
public static options: InitOptions; public static readonly options: InitOptions;
/** /**
* The attributes of the model * The attributes of the model
*/ */
public static rawAttributes: { [attribute: string]: ModelAttributeColumnOptions }; public static readonly rawAttributes: { [attribute: string]: ModelAttributeColumnOptions };
/**
* Reference to the sequelize instance the model was initialized with
*/
public static readonly sequelize?: Sequelize;
/** /**
* Initialize a model, representing a table in the DB, with attributes and options. * Initialize a model, representing a table in the DB, with attributes and options.
* *
* The table columns are defined by the hash that is given as the second argument. Each attribute of the hash represents a column. A short table definition might look like this: * The table columns are define by the hash that is given as the second argument. Each attribute of the hash represents a column. A short table definition might look like this:
* *
* ```js * ```js
* Project.init({ * Project.init({
...@@ -2370,7 +2392,7 @@ export abstract class Model<T = any, T2 = any> extends Hooks { ...@@ -2370,7 +2392,7 @@ export abstract class Model<T = any, T2 = any> extends Hooks {
* @param options.plain If set to true, included instances will be returned as plain objects * @param options.plain If set to true, included instances will be returned as plain objects
*/ */
public get(options?: { plain?: boolean; clone?: boolean }): object; public get(options?: { plain?: boolean; clone?: boolean }): object;
public get(key: string, options?: { plain?: boolean; clone?: boolean }): any; public get(key: string, options?: { plain?: boolean; clone?: boolean }): unknown;
public get<K extends keyof this>(key: K, options?: { plain?: boolean; clone?: boolean }): this[K]; public get<K extends keyof this>(key: K, options?: { plain?: boolean; clone?: boolean }): this[K];
/** /**
......
import { DataType } from './data-types'; import { DataType } from './data-types';
import { Logging, Model, ModelAttributeColumnOptions, ModelAttributes, Transactionable, WhereOptions } from './model'; import { Logging, Model, ModelAttributeColumnOptions, ModelAttributes, Transactionable, WhereOptions, Filterable } from './model';
import { Promise } from './promise'; import { Promise } from './promise';
import QueryTypes = require('./query-types'); import QueryTypes = require('./query-types');
import { Sequelize } from './sequelize'; import { Sequelize } from './sequelize';
...@@ -57,6 +57,10 @@ export interface QueryOptions extends Logging, Transactionable { ...@@ -57,6 +57,10 @@ export interface QueryOptions extends Logging, Transactionable {
instance?: Model; instance?: Model;
} }
export interface QueryOptionsWithWhere extends QueryOptions, Filterable {
}
export interface QueryOptionsWithModel { export interface QueryOptionsWithModel {
/** /**
* A sequelize model used to build the returned model instances (used to be called callee) * A sequelize model used to build the returned model instances (used to be called callee)
...@@ -73,9 +77,9 @@ export interface QueryOptionsWithType<T extends QueryTypes> extends QueryOptions ...@@ -73,9 +77,9 @@ export interface QueryOptionsWithType<T extends QueryTypes> extends QueryOptions
} }
/** /**
* Most of the methods accept options and use only the logger property of the options. That's why the most used * Most of the methods accept options and use only the logger property of the options. That's why the most used
* interface type for options in a method is separated here as another interface. * interface type for options in a method is separated here as another interface.
*/ */
export interface QueryInterfaceOptions extends Logging, Transactionable {} export interface QueryInterfaceOptions extends Logging, Transactionable {}
export interface CollateCharsetOptions { export interface CollateCharsetOptions {
...@@ -126,7 +130,7 @@ export interface AddUniqueConstraintOptions { ...@@ -126,7 +130,7 @@ export interface AddUniqueConstraintOptions {
export interface AddDefaultConstraintOptions { export interface AddDefaultConstraintOptions {
type: 'default'; type: 'default';
name?: string; name?: string;
defaultValue?: any; defaultValue?: unknown;
} }
export interface AddCheckConstraintOptions { export interface AddCheckConstraintOptions {
...@@ -152,29 +156,35 @@ export interface AddForeignKeyConstraintOptions { ...@@ -152,29 +156,35 @@ export interface AddForeignKeyConstraintOptions {
} }
export type AddConstraintOptions = export type AddConstraintOptions =
| AddUniqueConstraintOptions | AddUniqueConstraintOptions
| AddDefaultConstraintOptions | AddDefaultConstraintOptions
| AddCheckConstraintOptions | AddCheckConstraintOptions
| AddPrimaryKeyConstraintOptions | AddPrimaryKeyConstraintOptions
| AddForeignKeyConstraintOptions; | AddForeignKeyConstraintOptions;
export interface CreateDatabaseOptions extends CollateCharsetOptions, QueryOptions { export interface CreateDatabaseOptions extends CollateCharsetOptions, QueryOptions {
encoding?: string; encoding?: string;
} }
export interface FunctionParam {
type: string;
name?: string;
direction?: string;
}
/** /**
* The interface that Sequelize uses to talk to all databases. * The interface that Sequelize uses to talk to all databases.
* *
* This interface is available through sequelize.QueryInterface. It should not be commonly used, but it's * This interface is available through sequelize.QueryInterface. It should not be commonly used, but it's
* referenced anyway, so it can be used. * referenced anyway, so it can be used.
*/ */
export class QueryInterface { export class QueryInterface {
/** /**
* Returns the dialect-specific sql generator. * Returns the dialect-specific sql generator.
* *
* We don't have a definition for the QueryGenerator, because I doubt it is commonly in use separately. * We don't have a definition for the QueryGenerator, because I doubt it is commonly in use separately.
*/ */
public QueryGenerator: any; public QueryGenerator: unknown;
/** /**
* Returns the current sequelize instance. * Returns the current sequelize instance.
...@@ -389,7 +399,7 @@ export class QueryInterface { ...@@ -389,7 +399,7 @@ export class QueryInterface {
instance: Model, instance: Model,
tableName: string, tableName: string,
values: object, values: object,
identifier: object, identifier: WhereOptions,
options?: QueryOptions options?: QueryOptions
): Promise<object>; ): Promise<object>;
...@@ -399,7 +409,7 @@ export class QueryInterface { ...@@ -399,7 +409,7 @@ export class QueryInterface {
public bulkUpdate( public bulkUpdate(
tableName: string, tableName: string,
values: object, values: object,
identifier: object, identifier: WhereOptions,
options?: QueryOptions, options?: QueryOptions,
attributes?: string[] | string attributes?: string[] | string
): Promise<object>; ): Promise<object>;
...@@ -407,14 +417,14 @@ export class QueryInterface { ...@@ -407,14 +417,14 @@ export class QueryInterface {
/** /**
* Deletes a row * Deletes a row
*/ */
public delete(instance: Model, tableName: string, identifier: object, options?: QueryOptions): Promise<object>; public delete(instance: Model | null, tableName: string, identifier: WhereOptions, options?: QueryOptions): Promise<object>;
/** /**
* Deletes multiple rows at once * Deletes multiple rows at once
*/ */
public bulkDelete( public bulkDelete(
tableName: string, tableName: string,
identifier: object, identifier: WhereOptions,
options?: QueryOptions, options?: QueryOptions,
model?: typeof Model model?: typeof Model
): Promise<object>; ): Promise<object>;
...@@ -422,7 +432,7 @@ export class QueryInterface { ...@@ -422,7 +432,7 @@ export class QueryInterface {
/** /**
* Returns selected rows * Returns selected rows
*/ */
public select(model: typeof Model, tableName: string, options?: QueryOptions): Promise<object[]>; public select(model: typeof Model | null, tableName: string, options?: QueryOptionsWithWhere): Promise<object[]>;
/** /**
* Increments a row value * Increments a row value
...@@ -431,7 +441,7 @@ export class QueryInterface { ...@@ -431,7 +441,7 @@ export class QueryInterface {
instance: Model, instance: Model,
tableName: string, tableName: string,
values: object, values: object,
identifier: object, identifier: WhereOptions,
options?: QueryOptions options?: QueryOptions
): Promise<object>; ): Promise<object>;
...@@ -440,7 +450,7 @@ export class QueryInterface { ...@@ -440,7 +450,7 @@ export class QueryInterface {
*/ */
public rawSelect( public rawSelect(
tableName: string, tableName: string,
options: QueryOptions, options: QueryOptionsWithWhere,
attributeSelector: string | string[], attributeSelector: string | string[],
model?: typeof Model model?: typeof Model
): Promise<string[]>; ): Promise<string[]>;
...@@ -453,9 +463,11 @@ export class QueryInterface { ...@@ -453,9 +463,11 @@ export class QueryInterface {
tableName: string, tableName: string,
triggerName: string, triggerName: string,
timingType: string, timingType: string,
fireOnArray: any[], fireOnArray: {
[key: string]: unknown;
}[],
functionName: string, functionName: string,
functionParams: any[], functionParams: FunctionParam[],
optionsArray: string[], optionsArray: string[],
options?: QueryInterfaceOptions options?: QueryInterfaceOptions
): Promise<void>; ): Promise<void>;
...@@ -480,7 +492,7 @@ export class QueryInterface { ...@@ -480,7 +492,7 @@ export class QueryInterface {
*/ */
public createFunction( public createFunction(
functionName: string, functionName: string,
params: any[], params: FunctionParam[],
returnType: string, returnType: string,
language: string, language: string,
body: string, body: string,
...@@ -490,14 +502,14 @@ export class QueryInterface { ...@@ -490,14 +502,14 @@ export class QueryInterface {
/** /**
* Postgres only. Drops a function * Postgres only. Drops a function
*/ */
public dropFunction(functionName: string, params: any[], options?: QueryInterfaceOptions): Promise<void>; public dropFunction(functionName: string, params: FunctionParam[], options?: QueryInterfaceOptions): Promise<void>;
/** /**
* Postgres only. Rename a function * Postgres only. Rename a function
*/ */
public renameFunction( public renameFunction(
oldFunctionName: string, oldFunctionName: string,
params: any[], params: FunctionParam[],
newFunctionName: string, newFunctionName: string,
options?: QueryInterfaceOptions options?: QueryInterfaceOptions
): Promise<void>; ): Promise<void>;
......
...@@ -83,7 +83,7 @@ export interface PoolOptions { ...@@ -83,7 +83,7 @@ export interface PoolOptions {
* A function that validates a connection. Called with client. The default function checks that client is an * A function that validates a connection. Called with client. The default function checks that client is an
* object, and that its state is not disconnected * object, and that its state is not disconnected
*/ */
validate?(client?: any): boolean; validate?(client?: unknown): boolean;
} }
/** /**
...@@ -131,7 +131,7 @@ export interface Config { ...@@ -131,7 +131,7 @@ export interface Config {
}; };
readonly protocol: 'tcp'; readonly protocol: 'tcp';
readonly native: boolean; readonly native: boolean;
readonly ssl: any; readonly ssl: boolean;
readonly replication: boolean; readonly replication: boolean;
readonly dialectModulePath: null | string; readonly dialectModulePath: null | string;
readonly keepDefaultTimezone?: boolean; readonly keepDefaultTimezone?: boolean;
...@@ -1052,14 +1052,14 @@ export class Sequelize extends Hooks { ...@@ -1052,14 +1052,14 @@ export class Sequelize extends Hooks {
* @param sql * @param sql
* @param options Query options * @param options Query options
*/ */
public query(sql: string | { query: string; values: any[] }, options: QueryOptionsWithType<QueryTypes.UPDATE>): Promise<[undefined, number]>; public query(sql: string | { query: string; values: unknown[] }, options: QueryOptionsWithType<QueryTypes.UPDATE>): Promise<[undefined, number]>;
public query(sql: string | { query: string; values: any[] }, options: QueryOptionsWithType<QueryTypes.BULKUPDATE>): Promise<number>; public query(sql: string | { query: string; values: unknown[] }, options: QueryOptionsWithType<QueryTypes.BULKUPDATE>): Promise<number>;
public query(sql: string | { query: string; values: any[] }, options: QueryOptionsWithType<QueryTypes.INSERT>): Promise<[number, number]>; public query(sql: string | { query: string; values: unknown[] }, options: QueryOptionsWithType<QueryTypes.INSERT>): Promise<[number, number]>;
public query(sql: string | { query: string; values: any[] }, options: QueryOptionsWithType<QueryTypes.UPSERT>): Promise<number>; public query(sql: string | { query: string; values: unknown[] }, options: QueryOptionsWithType<QueryTypes.UPSERT>): Promise<number>;
public query(sql: string | { query: string; values: any[] }, options: QueryOptionsWithType<QueryTypes.DELETE>): Promise<void>; public query(sql: string | { query: string; values: unknown[] }, options: QueryOptionsWithType<QueryTypes.DELETE>): Promise<void>;
public query(sql: string | { query: string; values: any[] }, options: QueryOptionsWithType<QueryTypes.BULKDELETE>): Promise<number>; public query(sql: string | { query: string; values: unknown[] }, options: QueryOptionsWithType<QueryTypes.BULKDELETE>): Promise<number>;
public query(sql: string | { query: string; values: any[] }, options: QueryOptionsWithType<QueryTypes.SHOWTABLES>): Promise<string[]>; public query(sql: string | { query: string; values: unknown[] }, options: QueryOptionsWithType<QueryTypes.SHOWTABLES>): Promise<string[]>;
public query(sql: string | { query: string; values: any[] }, options: QueryOptionsWithType<QueryTypes.DESCRIBE>): Promise<{ public query(sql: string | { query: string; values: unknown[] }, options: QueryOptionsWithType<QueryTypes.DESCRIBE>): Promise<{
[key: string]: { [key: string]: {
type: string; type: string;
allowNull: boolean; allowNull: boolean;
...@@ -1070,11 +1070,11 @@ export class Sequelize extends Hooks { ...@@ -1070,11 +1070,11 @@ export class Sequelize extends Hooks {
} }
}>; }>;
public query<M extends Model>( public query<M extends Model>(
sql: string | { query: string; values: any[] }, sql: string | { query: string; values: unknown[] },
options: QueryOptionsWithModel options: QueryOptionsWithModel
): Promise<M[]>; ): Promise<M[]>;
public query<T extends object>(sql: string | { query: string; values: any[] }, options: QueryOptionsWithType<QueryTypes.SELECT>): Promise<T[]>; public query<T extends object>(sql: string | { query: string; values: unknown[] }, options: QueryOptionsWithType<QueryTypes.SELECT>): Promise<T[]>;
public query(sql: string | { query: string; values: any[] }, options?: QueryOptions | QueryOptionsWithType<QueryTypes.RAW>): Promise<unknown[]>; public query(sql: string | { query: string; values: unknown[] }, options?: QueryOptions | QueryOptionsWithType<QueryTypes.RAW>): Promise<unknown[]>;
/** /**
* Execute a query which would set an environment or user variable. The variables are set per connection, * Execute a query which would set an environment or user variable. The variables are set per connection,
...@@ -1251,7 +1251,7 @@ export class Sequelize extends Hooks { ...@@ -1251,7 +1251,7 @@ export class Sequelize extends Hooks {
* @param fn The function you want to call * @param fn The function you want to call
* @param args All further arguments will be passed as arguments to the function * @param args All further arguments will be passed as arguments to the function
*/ */
export function fn(fn: string, ...args: any[]): Fn; export function fn(fn: string, ...args: unknown[]): Fn;
/** /**
* Creates a object representing a column in the DB. This is often useful in conjunction with * Creates a object representing a column in the DB. This is often useful in conjunction with
...@@ -1267,14 +1267,14 @@ export function col(col: string): Col; ...@@ -1267,14 +1267,14 @@ export function col(col: string): Col;
* @param val The value to cast * @param val The value to cast
* @param type The type to cast it to * @param type The type to cast it to
*/ */
export function cast(val: any, type: string): Cast; export function cast(val: unknown, type: string): Cast;
/** /**
* Creates a object representing a literal, i.e. something that will not be escaped. * Creates a object representing a literal, i.e. something that will not be escaped.
* *
* @param val * @param val
*/ */
export function literal(val: any): Literal; export function literal(val: string): Literal;
/** /**
* An AND query * An AND query
......
export type Escapable = undefined | null | boolean | number | string | Date; export type Escapable = undefined | null | boolean | number | string | Date;
export function escapeId(val: string, forbidQualified?: boolean): string; export function escapeId(val: string, forbidQualified?: boolean): string;
export function escape(val: Escapable | Escapable[], timeZone?: string, dialect?: string, format?: string): string; export function escape(val: Escapable | Escapable[], timeZone?: string, dialect?: string, format?: string): string;
export function format(sql: string, values: any[], timeZone?: string, dialect?: string): string; export function format(sql: string, values: unknown[], timeZone?: string, dialect?: string): string;
export function formatNamedParameters(sql: string, values: any[], timeZone?: string, dialect?: string): string; export function formatNamedParameters(sql: string, values: unknown[], timeZone?: string, dialect?: string): string;
import { DataType } from './data-types'; import { DataType } from './data-types';
import { Model, WhereOptions } from './model';
export type Primitive = 'string' | 'number' | 'boolean'; export type Primitive = 'string' | 'number' | 'boolean';
...@@ -21,17 +22,22 @@ export function format(arr: string[], dialect: string): string; ...@@ -21,17 +22,22 @@ export function format(arr: string[], dialect: string): string;
export function formatNamedParameters(sql: string, parameters: { export function formatNamedParameters(sql: string, parameters: {
[key: string]: string | number | boolean; [key: string]: string | number | boolean;
}, dialect: string): string; }, dialect: string): string;
export function cloneDeep<T>(obj: T, fn?: (el: any) => any): T; export function cloneDeep<T>(obj: T, fn?: (el: unknown) => unknown): T;
export interface OptionsForMapping {
attributes?: string[];
where?: WhereOptions;
}
/** Expand and normalize finder options */ /** Expand and normalize finder options */
export function mapFinderOptions(options: any, Model: any): any; export function mapFinderOptions<T extends OptionsForMapping>(options: T, model: typeof Model): T;
/* Used to map field names in attributes and where conditions */ /* Used to map field names in attributes and where conditions */
export function mapOptionFieldNames(options: any, Model: any): any; export function mapOptionFieldNames<T extends OptionsForMapping>(options: T, model: typeof Model): T;
export function mapWhereFieldNames(attributes: any, Model: any): any; export function mapWhereFieldNames(attributes: object, model: typeof Model): object;
/** Used to map field names in values */ /** Used to map field names in values */
export function mapValueFieldNames(dataValues: any, fields: any, Model: any): any; export function mapValueFieldNames(dataValues: object, fields: string[], model: typeof Model): object;
export function isColString(value: string): boolean; export function isColString(value: string): boolean;
export function canTreatArrayAsAnd(arr: unknown[]): boolean; export function canTreatArrayAsAnd(arr: unknown[]): boolean;
...@@ -40,7 +46,7 @@ export function combineTableNames(tableName1: string, tableName2: string): strin ...@@ -40,7 +46,7 @@ export function combineTableNames(tableName1: string, tableName2: string): strin
export function singularize(s: string): string; export function singularize(s: string): string;
export function pluralize(s: string): string; export function pluralize(s: string): string;
export function toDefaultValue(value: any): any; export function toDefaultValue<T>(value: unknown): unknown;
/** /**
* Determine if the default value provided exists and can be described * Determine if the default value provided exists and can be described
...@@ -67,7 +73,7 @@ export class SequelizeMethod { ...@@ -67,7 +73,7 @@ export class SequelizeMethod {
* Please do not use these functions directly, use Sequelize.fn and Sequelize.col instead. * Please do not use these functions directly, use Sequelize.fn and Sequelize.col instead.
*/ */
export class Fn extends SequelizeMethod { export class Fn extends SequelizeMethod {
constructor(fn: string, args: any); constructor(fn: string, args: unknown[]);
public clone(): this; public clone(): this;
} }
...@@ -77,14 +83,14 @@ export class Col extends SequelizeMethod { ...@@ -77,14 +83,14 @@ export class Col extends SequelizeMethod {
} }
export class Cast extends SequelizeMethod { export class Cast extends SequelizeMethod {
public val: any; public val: unknown;
public type: string; public type: string;
constructor(val: any, type?: string); constructor(val: unknown, type?: string);
} }
export class Literal extends SequelizeMethod { export class Literal extends SequelizeMethod {
public val: any; public val: unknown;
constructor(val: any); constructor(val: unknown);
} }
export class Json extends SequelizeMethod { export class Json extends SequelizeMethod {
......
...@@ -14,7 +14,7 @@ interface User extends Model { ...@@ -14,7 +14,7 @@ interface User extends Model {
type UserModel = { type UserModel = {
new (): User new (): User
customStaticMethod(): any customStaticMethod(): unknown
} & typeof Model; } & typeof Model;
const User = sequelize.define('User', { firstName: DataTypes.STRING }, { tableName: 'users' }) as UserModel; const User = sequelize.define('User', { firstName: DataTypes.STRING }, { tableName: 'users' }) as UserModel;
......
...@@ -9,6 +9,9 @@ MyModel.findAll({ ...@@ -9,6 +9,9 @@ MyModel.findAll({
{ {
limit: 1, limit: 1,
model: AssociatedModel, model: AssociatedModel,
on: {
a: 1,
},
order: [['id', 'DESC']], order: [['id', 'DESC']],
separate: true, separate: true,
where: { state: Sequelize.col('project.state') }, where: { state: Sequelize.col('project.state') },
......
import { Association, HasOne, Model } from 'sequelize';
class MyModel extends Model {
public static associations: {
other: HasOne;
};
public static async customStuff() {
return this.sequelize!.query('select 1');
}
}
const assoc: Association = MyModel.associations.other;
...@@ -36,6 +36,16 @@ User.init( ...@@ -36,6 +36,16 @@ User.init(
username: DataTypes.STRING, username: DataTypes.STRING,
}, },
{ {
getterMethods: {
a() {
return 1;
},
},
setterMethods: {
b(val: string) {
(<User>this).username = val;
},
},
scopes: { scopes: {
custom(a: number) { custom(a: number) {
return { return {
......
...@@ -148,3 +148,15 @@ queryInterface.addConstraint('Person', ['firstname', 'lastname'], { ...@@ -148,3 +148,15 @@ queryInterface.addConstraint('Person', ['firstname', 'lastname'], {
}); });
queryInterface.removeConstraint('Person', 'firstnamexlastname'); queryInterface.removeConstraint('Person', 'firstnamexlastname');
queryInterface.select(null, 'Person', {
where: {
a: 1,
},
});
queryInterface.delete(null, 'Person', {
where: {
a: 1,
},
});
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!