Skip to content

Commit

Permalink
fix(types): fix QueryInterface#bulkInsert attribute arg type (#13945)
Browse files Browse the repository at this point in the history
Co-authored-by: Rik Smale <13023439+WikiRik@users.noreply.github.com>
  • Loading branch information
ChristopherChudzicki and WikiRik committed Jan 14, 2022
1 parent 6eb0186 commit 36ad644
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
5 changes: 3 additions & 2 deletions types/lib/data-types.d.ts
Expand Up @@ -52,6 +52,8 @@ export const ABSTRACT: AbstractDataTypeConstructor;
interface AbstractDataTypeConstructor {
key: string;
warn(link: string, text: string): void;
new (): AbstractDataType;
(): AbstractDataType;
}

export interface AbstractDataType {
Expand Down Expand Up @@ -336,7 +338,7 @@ interface DateDataTypeConstructor extends AbstractDataTypeConstructor {
(options?: DateDataTypeOptions): DateDataType;
}

export interface DateDataType extends AbstractDataTypeConstructor {
export interface DateDataType extends AbstractDataType {
options: DateDataTypeOptions;
}

Expand Down Expand Up @@ -367,7 +369,6 @@ export const HSTORE: AbstractDataTypeConstructor;
* A JSON string column. Only available in postgres.
*/
export const JSON: AbstractDataTypeConstructor;

/**
* A pre-processed JSON data column. Only available in postgres.
*/
Expand Down
2 changes: 1 addition & 1 deletion types/lib/query-interface.d.ts
Expand Up @@ -497,7 +497,7 @@ export class QueryInterface {
tableName: TableName,
records: object[],
options?: QueryOptions,
attributes?: string[] | string
attributes?: Record<string, ModelAttributeColumnOptions>
): Promise<object | number>;

/**
Expand Down
30 changes: 29 additions & 1 deletion types/test/data-types.ts
@@ -1,7 +1,7 @@
import { expectTypeOf } from 'expect-type';
import { DataTypes } from 'sequelize';

const { TINYINT, SMALLINT, MEDIUMINT, BIGINT, INTEGER } = DataTypes;
const { TINYINT, SMALLINT, MEDIUMINT, BIGINT, INTEGER, JSON, JSONB, CITEXT, MACADDR, TSVECTOR, CIDR, INET } = DataTypes;

// TINYINT
expectTypeOf(TINYINT()).toEqualTypeOf<DataTypes.TinyIntegerDataType>();
Expand Down Expand Up @@ -32,3 +32,31 @@ expectTypeOf(INTEGER()).toEqualTypeOf<DataTypes.IntegerDataType>();
expectTypeOf(new INTEGER()).toEqualTypeOf<DataTypes.IntegerDataType>();
expectTypeOf(INTEGER.UNSIGNED.ZEROFILL()).toEqualTypeOf<DataTypes.IntegerDataType>();
expectTypeOf(new INTEGER.UNSIGNED.ZEROFILL()).toEqualTypeOf<DataTypes.IntegerDataType>();

// JSON
expectTypeOf(new JSON()).toEqualTypeOf<DataTypes.AbstractDataType>();
expectTypeOf(JSON()).toEqualTypeOf<DataTypes.AbstractDataType>();

// JSONB
expectTypeOf(new JSONB()).toEqualTypeOf<DataTypes.AbstractDataType>();
expectTypeOf(JSONB()).toEqualTypeOf<DataTypes.AbstractDataType>();

// CITEXT
expectTypeOf(new CITEXT()).toEqualTypeOf<DataTypes.AbstractDataType>();
expectTypeOf(CITEXT()).toEqualTypeOf<DataTypes.AbstractDataType>();

// MACADDR
expectTypeOf(new MACADDR()).toEqualTypeOf<DataTypes.AbstractDataType>();
expectTypeOf(MACADDR()).toEqualTypeOf<DataTypes.AbstractDataType>();

// TSVECTOR
expectTypeOf(new TSVECTOR()).toEqualTypeOf<DataTypes.AbstractDataType>();
expectTypeOf(TSVECTOR()).toEqualTypeOf<DataTypes.AbstractDataType>();

// CIDR
expectTypeOf(new CIDR()).toEqualTypeOf<DataTypes.AbstractDataType>();
expectTypeOf(CIDR()).toEqualTypeOf<DataTypes.AbstractDataType>();

// INET
expectTypeOf(new INET()).toEqualTypeOf<DataTypes.AbstractDataType>();
expectTypeOf(INET()).toEqualTypeOf<DataTypes.AbstractDataType>();
2 changes: 2 additions & 0 deletions types/test/query-interface.ts
Expand Up @@ -67,6 +67,8 @@ async function test() {

const bulkInsertRes: Promise<number | object> = queryInterface.bulkInsert({ tableName: 'foo', as: 'bar', name: 'as' }, [{}], {});

const bulkInsertResWithAttrs: Promise<number | object> = queryInterface.bulkInsert('foo', [{}], {}, { bar: { type: DataTypes.JSON } });

await queryInterface.bulkUpdate({ tableName: 'foo', delimiter: 'bar', as: 'baz', name: 'quz' }, {}, {});

await queryInterface.dropTrigger({ tableName: 'foo', as: 'bar', name: 'baz' }, 'foo', {});
Expand Down

0 comments on commit 36ad644

Please sign in to comment.