Skip to content

Commit

Permalink
fix(types): add instance member declaration (sequelize#13684)
Browse files Browse the repository at this point in the history
* fix(types): add instance member declaration

* test(types): add static/instance members test cases

Co-authored-by: Sascha Depold <sdepold@users.noreply.github.com>
  • Loading branch information
2 people authored and aliatsis committed Jun 2, 2022
1 parent 836f031 commit 9b2cc39
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
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

0 comments on commit 9b2cc39

Please sign in to comment.