Skip to content

Commit

Permalink
Merge branch 'master' into fix-model
Browse files Browse the repository at this point in the history
  • Loading branch information
theoludwig authored Feb 14, 2021
2 parents c65f875 + 7c467d4 commit 9fb9f44
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 4 deletions.
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
4 changes: 2 additions & 2 deletions src/model/table/table-options.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {ModelOptions} from "sequelize";
import {Model, ModelOptions} from "sequelize";

export interface TableOptions extends ModelOptions {
export interface TableOptions<M extends Model = Model> extends ModelOptions<M> {
modelName?: string;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/model/table/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {TableOptions} from "./table-options";
import {Model} from "../model/model";
import {setModelName, addOptions} from "../shared/model-service";

export function Table(options: TableOptions): Function;
export function Table<M extends Model = Model>(options: TableOptions<M>): Function;
export function Table(target: Function): void;
export function Table(arg: any): void | Function {

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
13 changes: 13 additions & 0 deletions test/types/model.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,16 @@ export class User extends Model {
@Column(DataType.ARRAY(DataType.STRING))
myCol: string[];
}

@Table<Post>({
hooks: {
beforeUpdate: (instance) => {
// without generic random will result in error
instance.random = 4;
},
},
})
export class Post extends Model {
@Column(DataType.INTEGER)
random: number;
}

0 comments on commit 9fb9f44

Please sign in to comment.