Skip to content

Commit

Permalink
feat: infer bigint data type (#893)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brobin authored Feb 14, 2021
1 parent 6547ffd commit 7c467d4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ Design type | Sequelize data type
`string` | `STRING`
`boolean` | `BOOLEAN`
`number` | `INTEGER`
`bigint` | `BIGINT`
`Date` | `DATE`
`Buffer` | `BLOB`

Expand Down
2 changes: 2 additions & 0 deletions src/sequelize/data-type/data-type-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
18 changes: 17 additions & 1 deletion test/specs/table_column.spec.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 7c467d4

Please sign in to comment.