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): fix QueryInterface#bulkInsert attribute arg type #13945

Merged
merged 9 commits into from Jan 14, 2022
10 changes: 7 additions & 3 deletions types/lib/data-types.d.ts
Expand Up @@ -366,12 +366,16 @@ export const HSTORE: AbstractDataTypeConstructor;
/**
* A JSON string column. Only available in postgres.
*/
export const JSON: AbstractDataTypeConstructor;

export const JSON: JSONDataTypeConstructor;
/**
* A pre-processed JSON data column. Only available in postgres.
*/
export const JSONB: AbstractDataTypeConstructor;
export const JSONB: JSONDataTypeConstructor;

interface JSONDataTypeConstructor extends AbstractDataTypeConstructor {
new (): AbstractDataType;
(): AbstractDataType;
}

/**
* A default value of the current timestamp
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
10 changes: 9 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 } = DataTypes;

// TINYINT
expectTypeOf(TINYINT()).toEqualTypeOf<DataTypes.TinyIntegerDataType>();
Expand Down Expand Up @@ -32,3 +32,11 @@ 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>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make sure that there is an empty line at the end of this file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, apparently I failed at the new-line even after re-requesting review. Looking into it... I have the newline locally, but it seems not to be showing up on github, which is confusing me. Looking into it....

I see what you meant 👍
Screen Shot 2022-01-13 at 6 19 09 PM

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