From 7c467d404a200b3153cc7aa2605d1e542bef3da9 Mon Sep 17 00:00:00 2001 From: Tobin Brown Date: Sun, 14 Feb 2021 03:13:02 -0600 Subject: [PATCH] feat: infer bigint data type (#893) --- README.md | 1 + src/sequelize/data-type/data-type-service.ts | 2 ++ test/specs/table_column.spec.ts | 18 +++++++++++++++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1a7ea3fc..4a98d26f 100644 --- a/README.md +++ b/README.md @@ -285,6 +285,7 @@ Design type | Sequelize data type `string` | `STRING` `boolean` | `BOOLEAN` `number` | `INTEGER` + `bigint` | `BIGINT` `Date` | `DATE` `Buffer` | `BLOB` diff --git a/src/sequelize/data-type/data-type-service.ts b/src/sequelize/data-type/data-type-service.ts index 00a2190c..5f15bc2f 100644 --- a/src/sequelize/data-type/data-type-service.ts +++ b/src/sequelize/data-type/data-type-service.ts @@ -18,6 +18,8 @@ export function inferDataType(designType: any): DataTypeAbstract | undefined { switch (designType) { case String: return DataTypes.STRING; + case BigInt: + return DataTypes.BIGINT; case Number: return DataTypes.INTEGER; case Boolean: diff --git a/test/specs/table_column.spec.ts b/test/specs/table_column.spec.ts index f9fb8738..845d5e13 100644 --- a/test/specs/table_column.spec.ts +++ b/test/specs/table_column.spec.ts @@ -1,7 +1,7 @@ import {expect, use} from 'chai'; import * as chaiAsPromised from 'chai-as-promised'; import {ModelAttributes} from 'sequelize'; -import {Model, Table, Column, DataType} from "../../src"; +import {Model, Table, Column, DataType, AutoIncrement, PrimaryKey} from "../../src"; import {createSequelize} from "../utils/sequelize"; import {User} from "../models/User"; import {getOptions} from "../../src/model/shared/model-service"; @@ -197,6 +197,22 @@ describe('table_column', () => { describe('column', () => { + it('should infer the correct data type for bigint', () => { + @Table + class BigIntModel extends Model { + @PrimaryKey + @AutoIncrement + @Column + id: bigint; + } + + sequelize.addModels([BigIntModel]); + + const attributes = getAttributes(BigIntModel.prototype); + + expect(attributes.id.type).to.equal(DataType.BIGINT); + }); + it('should create appropriate sql query', () => { const seq = createSequelize(false);