Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(types): add instance member declaration #13684

Merged
merged 3 commits into from Nov 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions types/lib/sequelize.d.ts
Expand Up @@ -426,6 +426,7 @@ export class Sequelize extends Hooks {
* @param args All further arguments will be passed as arguments to the function
*/
public static fn: typeof fn;
public fn: typeof fn;

/**
* Creates a object representing a column in the DB. This is often useful in conjunction with
Expand All @@ -434,6 +435,7 @@ export class Sequelize extends Hooks {
* @param col The name of the column
*/
public static col: typeof col;
public col: typeof col;

/**
* Creates a object representing a call to the cast function.
Expand All @@ -442,27 +444,31 @@ export class Sequelize extends Hooks {
* @param type The type to cast it to
*/
public static cast: typeof cast;
public cast: typeof cast;

/**
* Creates a object representing a literal, i.e. something that will not be escaped.
*
* @param val
*/
public static literal: typeof literal;
public literal: typeof literal;

/**
* An AND query
*
* @param args Each argument will be joined by AND
*/
public static and: typeof and;
public and: typeof and;

/**
* An OR query
*
* @param args Each argument will be joined by OR
*/
public static or: typeof or;
public or: typeof or;

/**
* Creates an object representing nested where conditions for postgres's json data-type.
Expand All @@ -473,6 +479,7 @@ export class Sequelize extends Hooks {
* '<value>'".
*/
public static json: typeof json;
public json: typeof json;

/**
* A way of specifying attr = condition.
Expand All @@ -493,6 +500,7 @@ export class Sequelize extends Hooks {
* etc.)
*/
public static where: typeof where;
public where: typeof where;

/**
* A hook that is run before validation
Expand Down
20 changes: 19 additions & 1 deletion types/test/sequelize.ts
@@ -1,4 +1,4 @@
import { Config, Sequelize, Model, QueryTypes, ModelCtor } from 'sequelize';
import { Config, Sequelize, Model, QueryTypes, ModelCtor, Op } from 'sequelize';
import { Fn } from 'sequelize/lib/utils';

Sequelize.useCLS({
Expand All @@ -20,6 +20,24 @@ export const sequelize = new Sequelize({
}
});

// static members
Sequelize.fn('max', Sequelize.col('age'))
Sequelize.literal('1-2')
Sequelize.cast('123', 'integer')
Sequelize.and()
Sequelize.or()
Sequelize.json('data.id')
Sequelize.where(Sequelize.col("ABS"), Op.is, null);

// instance members
sequelize.fn('max', sequelize.col('age'))
sequelize.literal('1-2')
sequelize.cast('123', 'integer')
sequelize.and()
sequelize.or()
sequelize.json('data.id')
sequelize.where(sequelize.col("ABS"), Op.is, null);

const databaseName = sequelize.getDatabaseName();

const conn = sequelize.connectionManager;
Expand Down