Skip to content

Commit 9fb9f44

Browse files
authored
Merge branch 'master' into fix-model
2 parents c65f875 + 7c467d4 commit 9fb9f44

File tree

6 files changed

+36
-4
lines changed

6 files changed

+36
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ Design type | Sequelize data type
285285
`string` | `STRING`
286286
`boolean` | `BOOLEAN`
287287
`number` | `INTEGER`
288+
`bigint` | `BIGINT`
288289
`Date` | `DATE`
289290
`Buffer` | `BLOB`
290291

src/model/table/table-options.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import {ModelOptions} from "sequelize";
1+
import {Model, ModelOptions} from "sequelize";
22

3-
export interface TableOptions extends ModelOptions {
3+
export interface TableOptions<M extends Model = Model> extends ModelOptions<M> {
44
modelName?: string;
55

66
/**

src/model/table/table.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {TableOptions} from "./table-options";
22
import {Model} from "../model/model";
33
import {setModelName, addOptions} from "../shared/model-service";
44

5-
export function Table(options: TableOptions): Function;
5+
export function Table<M extends Model = Model>(options: TableOptions<M>): Function;
66
export function Table(target: Function): void;
77
export function Table(arg: any): void | Function {
88

src/sequelize/data-type/data-type-service.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ export function inferDataType(designType: any): DataTypeAbstract | undefined {
1818
switch (designType) {
1919
case String:
2020
return DataTypes.STRING;
21+
case BigInt:
22+
return DataTypes.BIGINT;
2123
case Number:
2224
return DataTypes.INTEGER;
2325
case Boolean:

test/specs/table_column.spec.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {expect, use} from 'chai';
22
import * as chaiAsPromised from 'chai-as-promised';
33
import {ModelAttributes} from 'sequelize';
4-
import {Model, Table, Column, DataType} from "../../src";
4+
import {Model, Table, Column, DataType, AutoIncrement, PrimaryKey} from "../../src";
55
import {createSequelize} from "../utils/sequelize";
66
import {User} from "../models/User";
77
import {getOptions} from "../../src/model/shared/model-service";
@@ -197,6 +197,22 @@ describe('table_column', () => {
197197

198198
describe('column', () => {
199199

200+
it('should infer the correct data type for bigint', () => {
201+
@Table
202+
class BigIntModel extends Model {
203+
@PrimaryKey
204+
@AutoIncrement
205+
@Column
206+
id: bigint;
207+
}
208+
209+
sequelize.addModels([BigIntModel]);
210+
211+
const attributes = getAttributes(BigIntModel.prototype);
212+
213+
expect(attributes.id.type).to.equal(DataType.BIGINT);
214+
});
215+
200216
it('should create appropriate sql query', () => {
201217

202218
const seq = createSequelize(false);

test/types/model.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,16 @@ export class User extends Model {
1010
@Column(DataType.ARRAY(DataType.STRING))
1111
myCol: string[];
1212
}
13+
14+
@Table<Post>({
15+
hooks: {
16+
beforeUpdate: (instance) => {
17+
// without generic random will result in error
18+
instance.random = 4;
19+
},
20+
},
21+
})
22+
export class Post extends Model {
23+
@Column(DataType.INTEGER)
24+
random: number;
25+
}

0 commit comments

Comments
 (0)