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

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', {
### 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
const sequelize = new Sequelize('database', 'username', 'password', {
......
......@@ -132,6 +132,10 @@ class Association {
});
}
[Symbol.for('nodejs.util.inspect.custom')]() {
return this.as;
}
inspect() {
return this.as;
}
......
......@@ -96,7 +96,7 @@ module.exports = BaseTypes => {
if (!(this instanceof DATEONLY)) {
return new DATEONLY();
}
BaseTypes.DATEONLY.apply(this, arguments);
BaseTypes.DATEONLY.call(this);
}
inherits(DATEONLY, BaseTypes.DATEONLY);
......@@ -109,7 +109,7 @@ module.exports = BaseTypes => {
if (!(this instanceof UUID)) {
return new UUID();
}
BaseTypes.UUID.apply(this, arguments);
BaseTypes.UUID.call(this);
}
inherits(UUID, BaseTypes.UUID);
......@@ -156,7 +156,7 @@ module.exports = BaseTypes => {
if (!(this instanceof JSONTYPE)) {
return new JSONTYPE();
}
BaseTypes.JSON.apply(this, arguments);
BaseTypes.JSON.call(this);
}
inherits(JSONTYPE, BaseTypes.JSON);
......
......@@ -116,7 +116,7 @@ module.exports = BaseTypes => {
function BOOLEAN() {
if (!(this instanceof BOOLEAN)) return new BOOLEAN();
BaseTypes.BOOLEAN.apply(this, arguments);
BaseTypes.BOOLEAN.call(this);
}
inherits(BOOLEAN, BaseTypes.BOOLEAN);
......@@ -126,7 +126,7 @@ module.exports = BaseTypes => {
function UUID() {
if (!(this instanceof UUID)) return new UUID();
BaseTypes.UUID.apply(this, arguments);
BaseTypes.UUID.call(this);
}
inherits(UUID, BaseTypes.UUID);
......@@ -136,7 +136,7 @@ module.exports = BaseTypes => {
function NOW() {
if (!(this instanceof NOW)) return new NOW();
BaseTypes.NOW.apply(this, arguments);
BaseTypes.NOW.call(this);
}
inherits(NOW, BaseTypes.NOW);
......@@ -156,7 +156,7 @@ module.exports = BaseTypes => {
function DATEONLY() {
if (!(this instanceof DATEONLY)) return new DATEONLY();
BaseTypes.DATEONLY.apply(this, arguments);
BaseTypes.DATEONLY.call(this);
}
inherits(DATEONLY, BaseTypes.DATEONLY);
......
......@@ -94,7 +94,7 @@ module.exports = BaseTypes => {
function DATEONLY() {
if (!(this instanceof DATEONLY)) return new DATEONLY();
BaseTypes.DATEONLY.apply(this, arguments);
BaseTypes.DATEONLY.call(this);
}
inherits(DATEONLY, BaseTypes.DATEONLY);
......@@ -104,7 +104,7 @@ module.exports = BaseTypes => {
function UUID() {
if (!(this instanceof UUID)) return new UUID();
BaseTypes.UUID.apply(this, arguments);
BaseTypes.UUID.call(this);
}
inherits(UUID, BaseTypes.UUID);
......@@ -164,7 +164,7 @@ module.exports = BaseTypes => {
function JSONTYPE() {
if (!(this instanceof JSONTYPE)) return new JSONTYPE();
BaseTypes.JSON.apply(this, arguments);
BaseTypes.JSON.call(this);
}
inherits(JSONTYPE, BaseTypes.JSON);
......
......@@ -41,7 +41,7 @@ module.exports = BaseTypes => {
function DATEONLY() {
if (!(this instanceof DATEONLY)) return new DATEONLY();
BaseTypes.DATEONLY.apply(this, arguments);
BaseTypes.DATEONLY.call(this);
}
inherits(DATEONLY, BaseTypes.DATEONLY);
......@@ -134,7 +134,7 @@ module.exports = BaseTypes => {
function CITEXT() {
if (!(this instanceof CITEXT)) return new CITEXT();
BaseTypes.CITEXT.apply(this, arguments);
BaseTypes.CITEXT.call(this);
}
inherits(CITEXT, BaseTypes.CITEXT);
......@@ -159,7 +159,7 @@ module.exports = BaseTypes => {
function BOOLEAN() {
if (!(this instanceof BOOLEAN)) return new BOOLEAN();
BaseTypes.BOOLEAN.apply(this, arguments);
BaseTypes.BOOLEAN.call(this);
}
inherits(BOOLEAN, BaseTypes.BOOLEAN);
......
......@@ -47,7 +47,7 @@ module.exports = BaseTypes => {
function JSONTYPE() {
if (!(this instanceof JSONTYPE)) return new JSONTYPE();
BaseTypes.JSON.apply(this, arguments);
BaseTypes.JSON.call(this);
}
inherits(JSONTYPE, BaseTypes.JSON);
......@@ -71,7 +71,7 @@ module.exports = BaseTypes => {
function DATEONLY() {
if (!(this instanceof DATEONLY)) return new DATEONLY();
BaseTypes.DATEONLY.apply(this, arguments);
BaseTypes.DATEONLY.call(this);
}
inherits(DATEONLY, BaseTypes.DATEONLY);
......@@ -108,7 +108,7 @@ module.exports = BaseTypes => {
function CITEXT() {
if (!(this instanceof CITEXT)) return new CITEXT();
BaseTypes.CITEXT.apply(this, arguments);
BaseTypes.CITEXT.call(this);
}
inherits(CITEXT, BaseTypes.CITEXT);
......
......@@ -27,9 +27,7 @@ class ModelManager {
attribute: 'name'
});
const model = this.models.filter(model => model[options.attribute] === against);
return model ? model[0] : null;
return this.models.find(model => model[options.attribute] === against);
}
get all() {
......
......@@ -3068,6 +3068,10 @@ class Model {
this._defaultsOptions(options, scope);
}
static [Symbol.for('nodejs.util.inspect.custom')]() {
return this.name;
}
static inspect() {
return this.name;
}
......
......@@ -50,9 +50,9 @@
"devDependencies": {
"@commitlint/cli": "^7.3.2",
"@commitlint/config-angular": "^7.3.1",
"@types/bluebird": "^3.5.25",
"@types/node": "^10.12.18",
"@types/validator": "^9.4.4",
"@types/bluebird": "^3.5.26",
"@types/node": "^10.12.27",
"@types/validator": "^10.9.0",
"chai": "^4.x",
"chai-as-promised": "^7.x",
"chai-datetime": "^1.x",
......@@ -72,18 +72,18 @@
"lcov-result-merger": "^3.0.0",
"lint-staged": "^8.1.0",
"mariadb": "^2.0.3",
"mocha": "^5.x",
"mysql2": "^1.6.4",
"mocha": "^6.0.2",
"mysql2": "^1.6.5",
"nyc": "^13.3.0",
"pg": "^7.8.0",
"pg-hstore": "^2.x",
"pg-types": "^2.0.0",
"rimraf": "^2.x",
"sinon": "^6.3.5",
"rimraf": "^2.6.3",
"sinon": "^7.2.4",
"sinon-chai": "^3.2.0",
"sqlite3": "^4.0.6",
"tedious": "^3.0.1",
"typescript": "^3.2.2"
"typescript": "^3.3.3333"
},
"keywords": [
"mysql",
......@@ -121,7 +121,7 @@
"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",
"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-mysql": "cross-env DIALECT=mysql npm run test-unit",
"test-unit-postgres": "cross-env DIALECT=postgres npm run test-unit",
......@@ -129,7 +129,7 @@
"test-unit-sqlite": "cross-env DIALECT=sqlite 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-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-mysql": "cross-env DIALECT=mysql npm run test-integration",
"test-integration-postgres": "cross-env DIALECT=postgres npm run test-integration",
......@@ -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-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-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-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-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 \"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\"",
"sscce": "env-cmd $npm_package_options_env_cmd node sscce.js",
"sscce-mariadb": "cross-env DIALECT=mariadb npm run sscce",
......
......@@ -101,7 +101,7 @@ export interface AssociationScope {
/**
* 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 {
* Attributes for the join table
*/
export interface JoinTableAttributes {
[attribute: string]: any;
[attribute: string]: unknown;
}
/**
......@@ -273,7 +273,7 @@ export interface BelongsToManyCreateAssociationMixinOptions extends CreateOption
* @see Instance
*/
export type BelongsToManyCreateAssociationMixin<TModel> = (
values?: { [attribute: string]: any },
values?: { [attribute: string]: unknown },
options?: BelongsToManyCreateAssociationMixinOptions
) => Promise<TModel>;
......
......@@ -116,7 +116,7 @@ export interface BelongsToCreateAssociationMixinOptions extends CreateOptions, B
* @see Instance
*/
export type BelongsToCreateAssociationMixin<TModel> = (
values?: { [attribute: string]: any },
values?: { [attribute: string]: unknown },
options?: BelongsToCreateAssociationMixinOptions
) => Promise<TModel>;
......
......@@ -205,7 +205,7 @@ export interface HasManyCreateAssociationMixinOptions extends CreateOptions {}
* @see Instance
*/
export type HasManyCreateAssociationMixin<TModel> = (
values?: { [attribute: string]: any },
values?: { [attribute: string]: unknown },
options?: HasManyCreateAssociationMixinOptions
) => Promise<TModel>;
......
......@@ -108,6 +108,6 @@ export interface HasOneCreateAssociationMixinOptions extends HasOneSetAssociatio
* @see Instance
*/
export type HasOneCreateAssociationMixin<TModel> = (
values?: { [attribute: string]: any },
values?: { [attribute: string]: unknown },
options?: HasOneCreateAssociationMixinOptions
) => Promise<TModel>;
......@@ -78,7 +78,7 @@ interface StringDataTypeConstructor extends AbstractDataTypeConstructor {
export interface StringDataType extends AbstractDataType {
options?: StringDataTypeOptions;
BINARY: this;
validate(value: any): boolean;
validate(value: unknown): boolean;
}
export interface StringDataTypeOptions {
......@@ -119,7 +119,7 @@ interface TextDataTypeConstructor extends AbstractDataTypeConstructor {
export interface TextDataType extends AbstractDataType {
options: TextDataTypeOptions;
validate(value: any): boolean;
validate(value: unknown): boolean;
}
export interface TextDataTypeOptions {
......@@ -134,14 +134,14 @@ interface NumberDataTypeConstructor extends AbstractDataTypeConstructor {
ZEROFILL: this;
new (options?: NumberDataTypeOptions): NumberDataType;
(options?: NumberDataTypeOptions): NumberDataType;
validate(value: any): boolean;
validate(value: unknown): boolean;
}
export interface NumberDataType extends AbstractDataType {
options: NumberDataTypeOptions;
UNSIGNED: this;
ZEROFILL: this;
validate(value: any): boolean;
validate(value: unknown): boolean;
}
export interface NumberDataTypeOptions {
......@@ -297,9 +297,9 @@ export const TIME: AbstractDataTypeConstructor;
export const DATE: DateDataTypeConstructor;
interface DateDataTypeConstructor extends AbstractDataTypeConstructor {
new (length?: any): DateDataType;
new (length?: string | number): DateDataType;
new (options?: DateDataTypeOptions): DateDataType;
(length?: any): DateDataType;
(length?: string | number): DateDataType;
(options?: DateDataTypeOptions): DateDataType;
}
......@@ -308,7 +308,7 @@ export interface DateDataType extends AbstractDataTypeConstructor {
}
export interface DateDataTypeOptions {
length?: any;
length?: string | number;
}
/**
......@@ -317,19 +317,13 @@ export interface DateDataTypeOptions {
export const DATEONLY: DateOnlyDataTypeConstructor;
interface DateOnlyDataTypeConstructor extends AbstractDataTypeConstructor {
new (length: any): DateOnlyDataType;
new (options: DateOnlyDataTypeOptions): DateOnlyDataType;
(length: any): DateOnlyDataType;
(options: DateOnlyDataTypeOptions): DateOnlyDataType;
new (): DateOnlyDataType;
(): DateOnlyDataType;
}
export interface DateOnlyDataType extends AbstractDataType {
options: DateOnlyDataTypeOptions;
}
export interface DateOnlyDataTypeOptions {
length?: any;
}
/**
* A key / value column. Only available in postgres.
......@@ -510,7 +504,7 @@ interface ArrayDataTypeConstructor extends AbstractDataTypeConstructor {
new <T extends AbstractDataTypeConstructor | AbstractDataType>(options: ArrayDataTypeOptions<T>): ArrayDataType<T>;
<T extends AbstractDataTypeConstructor | AbstractDataType>(type: 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 {
......
......@@ -93,7 +93,7 @@ export interface UniqueConstraintErrorOptions {
parent?: Error;
message?: string;
errors?: ValidationErrorItem[];
fields?: { [key: string]: any };
fields?: { [key: string]: unknown };
original?: Error;
}
......@@ -104,7 +104,7 @@ export class UniqueConstraintError extends ValidationError implements CommonErro
public readonly parent: Error;
public readonly original: Error;
public readonly sql: string;
public readonly fields: { [key: string]: any };
public readonly fields: { [key: string]: unknown };
constructor(options?: UniqueConstraintErrorOptions);
}
......@@ -114,7 +114,7 @@ export class UniqueConstraintError extends ValidationError implements CommonErro
export class ForeignKeyConstraintError extends DatabaseError {
public table: string;
public fields: { [field: string]: string };
public value: any;
public value: unknown;
public index: string;
constructor(options: { parent?: Error; message?: string; index?: string; fields?: string[]; table?: string });
}
......
......@@ -54,7 +54,7 @@ export interface AllModelHooks extends ModelHookOptions {
export interface SequelizeHooks extends AllModelHooks {
beforeConnect(config: Config): HookReturn;
afterConnect(connection: any, config: Config): HookReturn;
afterConnect(connection: unknown, config: Config): HookReturn;
}
/**
......
......@@ -9,7 +9,7 @@ export class ModelManager {
constructor(sequelize: Sequelize);
public addModel<T extends typeof Model>(model: T): T;
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;
......@@ -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
* 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 {
*
* Example: `[Op.contains]: [1, 2]` becomes `@> [1, 2]`
*/
[Op.contains]?: any[];
[Op.contains]?: [number, number] | [Date, Date];
/**
* PG array contained by operator
*
* Example: `[Op.contained]: [1, 2]` becomes `<@ [1, 2]`
*/
[Op.contained]?: any[];
[Op.contained]?: [number, number] | [Date, Date];
/** Example: `[Op.gt]: 6,` becomes `> 6` */
[Op.gt]?: number | string | Date;
......@@ -322,6 +322,11 @@ export interface IncludeOptions extends Filterable, Projectable {
association?: Association;
/**
* Custom `on` clause, overrides default.
*/
on?: WhereOptions;
/**
* Note that this converts the eager load to an inner join,
* unless you explicitly set `required: false`
*/
......@@ -997,14 +1002,14 @@ export interface ModelValidateOptions {
* We can't enforce any other method to be a function, so :
*
* ```typescript
* [name: string] : ( value : any ) => boolean;
* [name: string] : ( value : unknown ) => boolean;
* ```
*
* doesn't work in combination with the properties above
*
* @see https://github.com/Microsoft/TypeScript/issues/1889
*/
[name: string]: any;
[name: string]: unknown;
}
/**
......@@ -1069,14 +1074,14 @@ export interface ModelNameOptions {
* Interface for getterMethods in DefineOptions
*/
export interface ModelGetterOptions {
[name: string]: () => any;
[name: string]: (this: Model) => unknown;
}
/**
* Interface for setterMethods in DefineOptions
*/
export interface ModelSetterOptions {
[name: string]: (val: any) => void;
[name: string]: (this: Model, val: any) => void;
}
/**
......@@ -1107,7 +1112,7 @@ export interface ColumnOptions {
/**
* 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 {
* Provide a custom getter for this column. Use `this.getDataValue(String)` to manipulate the underlying
* values.
*/
get?(): any;
get?(): unknown;
/**
* Provide a custom setter for this column. Use `this.setDataValue(String, Value)` to manipulate the
* underlying values.
*/
set?(val: any): void;
set?(val: unknown): void;
}
/**
......@@ -1351,6 +1356,16 @@ export interface ModelOptions<M extends Model = Model> {
* accepts an optional error.
*/
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 {
export abstract class Model<T = any, T2 = any> extends Hooks {
/** The name of the database table */
public static tableName: string;
public static readonly tableName: string;
/**
* The name of the primary key attribute
*/
public static primaryKeyAttribute: string;
public static readonly primaryKeyAttribute: string;
/**
* 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
*/
public static options: InitOptions;
public static readonly options: InitOptions;
/**
* 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.
*
* 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
* Project.init({
......@@ -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
*/
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];
/**
......
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 QueryTypes = require('./query-types');
import { Sequelize } from './sequelize';
......@@ -57,6 +57,10 @@ export interface QueryOptions extends Logging, Transactionable {
instance?: Model;
}
export interface QueryOptionsWithWhere extends QueryOptions, Filterable {
}
export interface QueryOptionsWithModel {
/**
* 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
}
/**
* 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.
*/
* 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.
*/
export interface QueryInterfaceOptions extends Logging, Transactionable {}
export interface CollateCharsetOptions {
......@@ -126,7 +130,7 @@ export interface AddUniqueConstraintOptions {
export interface AddDefaultConstraintOptions {
type: 'default';
name?: string;
defaultValue?: any;
defaultValue?: unknown;
}
export interface AddCheckConstraintOptions {
......@@ -152,29 +156,35 @@ export interface AddForeignKeyConstraintOptions {
}
export type AddConstraintOptions =
| AddUniqueConstraintOptions
| AddDefaultConstraintOptions
| AddCheckConstraintOptions
| AddPrimaryKeyConstraintOptions
| AddForeignKeyConstraintOptions;
| AddUniqueConstraintOptions
| AddDefaultConstraintOptions
| AddCheckConstraintOptions
| AddPrimaryKeyConstraintOptions
| AddForeignKeyConstraintOptions;
export interface CreateDatabaseOptions extends CollateCharsetOptions, QueryOptions {
encoding?: string;
}
export interface FunctionParam {
type: string;
name?: string;
direction?: string;
}
/**
* 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
* referenced anyway, so it can be used.
*/
* 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
* referenced anyway, so it can be used.
*/
export class QueryInterface {
/**
* Returns the dialect-specific sql generator.
*
* 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.
......@@ -389,7 +399,7 @@ export class QueryInterface {
instance: Model,
tableName: string,
values: object,
identifier: object,
identifier: WhereOptions,
options?: QueryOptions
): Promise<object>;
......@@ -399,7 +409,7 @@ export class QueryInterface {
public bulkUpdate(
tableName: string,
values: object,
identifier: object,
identifier: WhereOptions,
options?: QueryOptions,
attributes?: string[] | string
): Promise<object>;
......@@ -407,14 +417,14 @@ export class QueryInterface {
/**
* 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
*/
public bulkDelete(
tableName: string,
identifier: object,
identifier: WhereOptions,
options?: QueryOptions,
model?: typeof Model
): Promise<object>;
......@@ -422,7 +432,7 @@ export class QueryInterface {
/**
* 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
......@@ -431,7 +441,7 @@ export class QueryInterface {
instance: Model,
tableName: string,
values: object,
identifier: object,
identifier: WhereOptions,
options?: QueryOptions
): Promise<object>;
......@@ -440,7 +450,7 @@ export class QueryInterface {
*/
public rawSelect(
tableName: string,
options: QueryOptions,
options: QueryOptionsWithWhere,
attributeSelector: string | string[],
model?: typeof Model
): Promise<string[]>;
......@@ -453,9 +463,11 @@ export class QueryInterface {
tableName: string,
triggerName: string,
timingType: string,
fireOnArray: any[],
fireOnArray: {
[key: string]: unknown;
}[],
functionName: string,
functionParams: any[],
functionParams: FunctionParam[],
optionsArray: string[],
options?: QueryInterfaceOptions
): Promise<void>;
......@@ -480,7 +492,7 @@ export class QueryInterface {
*/
public createFunction(
functionName: string,
params: any[],
params: FunctionParam[],
returnType: string,
language: string,
body: string,
......@@ -490,14 +502,14 @@ export class QueryInterface {
/**
* 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
*/
public renameFunction(
oldFunctionName: string,
params: any[],
params: FunctionParam[],
newFunctionName: string,
options?: QueryInterfaceOptions
): Promise<void>;
......
......@@ -83,7 +83,7 @@ export interface PoolOptions {
* 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
*/
validate?(client?: any): boolean;
validate?(client?: unknown): boolean;
}
/**
......@@ -131,7 +131,7 @@ export interface Config {
};
readonly protocol: 'tcp';
readonly native: boolean;
readonly ssl: any;
readonly ssl: boolean;
readonly replication: boolean;
readonly dialectModulePath: null | string;
readonly keepDefaultTimezone?: boolean;
......@@ -1052,14 +1052,14 @@ export class Sequelize extends Hooks {
* @param sql
* @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: any[] }, 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: any[] }, 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: any[] }, 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: any[] }, options: QueryOptionsWithType<QueryTypes.DESCRIBE>): Promise<{
public query(sql: string | { query: string; values: unknown[] }, options: QueryOptionsWithType<QueryTypes.UPDATE>): Promise<[undefined, number]>;
public query(sql: string | { query: string; values: unknown[] }, options: QueryOptionsWithType<QueryTypes.BULKUPDATE>): Promise<number>;
public query(sql: string | { query: string; values: unknown[] }, options: QueryOptionsWithType<QueryTypes.INSERT>): Promise<[number, number]>;
public query(sql: string | { query: string; values: unknown[] }, options: QueryOptionsWithType<QueryTypes.UPSERT>): Promise<number>;
public query(sql: string | { query: string; values: unknown[] }, options: QueryOptionsWithType<QueryTypes.DELETE>): Promise<void>;
public query(sql: string | { query: string; values: unknown[] }, options: QueryOptionsWithType<QueryTypes.BULKDELETE>): Promise<number>;
public query(sql: string | { query: string; values: unknown[] }, options: QueryOptionsWithType<QueryTypes.SHOWTABLES>): Promise<string[]>;
public query(sql: string | { query: string; values: unknown[] }, options: QueryOptionsWithType<QueryTypes.DESCRIBE>): Promise<{
[key: string]: {
type: string;
allowNull: boolean;
......@@ -1070,11 +1070,11 @@ export class Sequelize extends Hooks {
}
}>;
public query<M extends Model>(
sql: string | { query: string; values: any[] },
sql: string | { query: string; values: unknown[] },
options: QueryOptionsWithModel
): Promise<M[]>;
public query<T extends object>(sql: string | { query: string; values: any[] }, options: QueryOptionsWithType<QueryTypes.SELECT>): Promise<T[]>;
public query(sql: string | { query: string; values: any[] }, options?: QueryOptions | QueryOptionsWithType<QueryTypes.RAW>): Promise<unknown[]>;
public query<T extends object>(sql: string | { query: string; values: unknown[] }, options: QueryOptionsWithType<QueryTypes.SELECT>): Promise<T[]>;
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,
......@@ -1251,7 +1251,7 @@ export class Sequelize extends Hooks {
* @param fn The function you want to call
* @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
......@@ -1267,14 +1267,14 @@ export function col(col: string): Col;
* @param val The value to cast
* @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.
*
* @param val
*/
export function literal(val: any): Literal;
export function literal(val: string): Literal;
/**
* An AND query
......
export type Escapable = undefined | null | boolean | number | string | Date;
export function escapeId(val: string, forbidQualified?: boolean): 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 formatNamedParameters(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: unknown[], timeZone?: string, dialect?: string): string;
import { DataType } from './data-types';
import { Model, WhereOptions } from './model';
export type Primitive = 'string' | 'number' | 'boolean';
......@@ -21,17 +22,22 @@ export function format(arr: string[], dialect: string): string;
export function formatNamedParameters(sql: string, parameters: {
[key: string]: string | number | boolean;
}, 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 */
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 */
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 */
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 canTreatArrayAsAnd(arr: unknown[]): boolean;
......@@ -40,7 +46,7 @@ export function combineTableNames(tableName1: string, tableName2: string): strin
export function singularize(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
......@@ -67,7 +73,7 @@ export class SequelizeMethod {
* Please do not use these functions directly, use Sequelize.fn and Sequelize.col instead.
*/
export class Fn extends SequelizeMethod {
constructor(fn: string, args: any);
constructor(fn: string, args: unknown[]);
public clone(): this;
}
......@@ -77,14 +83,14 @@ export class Col extends SequelizeMethod {
}
export class Cast extends SequelizeMethod {
public val: any;
public val: unknown;
public type: string;
constructor(val: any, type?: string);
constructor(val: unknown, type?: string);
}
export class Literal extends SequelizeMethod {
public val: any;
constructor(val: any);
public val: unknown;
constructor(val: unknown);
}
export class Json extends SequelizeMethod {
......
......@@ -14,7 +14,7 @@ interface User extends Model {
type UserModel = {
new (): User
customStaticMethod(): any
customStaticMethod(): unknown
} & typeof Model;
const User = sequelize.define('User', { firstName: DataTypes.STRING }, { tableName: 'users' }) as UserModel;
......
......@@ -9,6 +9,9 @@ MyModel.findAll({
{
limit: 1,
model: AssociatedModel,
on: {
a: 1,
},
order: [['id', 'DESC']],
separate: true,
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(
username: DataTypes.STRING,
},
{
getterMethods: {
a() {
return 1;
},
},
setterMethods: {
b(val: string) {
(<User>this).username = val;
},
},
scopes: {
custom(a: number) {
return {
......
......@@ -148,3 +148,15 @@ queryInterface.addConstraint('Person', ['firstname', 'lastname'], {
});
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!