Skip to content

Commit 1621c3f

Browse files
committed
Upgrade to Sequelize 6
1 parent 883cb2c commit 1621c3f

File tree

8 files changed

+46
-37
lines changed

8 files changed

+46
-37
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,7 @@ npm-debug.log
2727
coverage
2828
.nyc_output
2929
!test/tsconfig.mocha.js
30+
31+
32+
# lockFile
33+
*.lock

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sequelize-typescript",
3-
"version": "1.1.0-beta.0",
3+
"version": "1.1.0-beta.1",
44
"description": "Decorators and some other features for sequelize",
55
"scripts": {
66
"build": "tsc",
@@ -61,11 +61,11 @@
6161
"nyc": "13.3.0",
6262
"prettyjson": "1.2.1",
6363
"reflect-metadata": "0.1.9",
64-
"sequelize": "5.15.1",
64+
"sequelize": "6.2.4",
6565
"sinon": "1.17.7",
6666
"sinon-chai": "2.8.0",
6767
"source-map-support": "0.4.14",
68-
"sqlite3": "4.0.4",
68+
"sqlite3": "5.0.0",
6969
"ts-node": "7.0.1",
7070
"tslint": "5.14.0",
7171
"typescript": "3.3.3",
@@ -76,10 +76,10 @@
7676
"@types/node": "*",
7777
"@types/validator": "*",
7878
"reflect-metadata": "*",
79-
"sequelize": "^5.1.0"
79+
"sequelize": "^6.0.0"
8080
},
8181
"engines": {
82-
"node": ">=0.8.15"
82+
"node": ">=10.0.0"
8383
},
8484
"nyc": {
8585
"lines": 85,

src/model/model/model.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {InitOptions, Model as OriginModel, ModelAttributes, FindOptions, BuildOptions, Promise} from 'sequelize';
1+
import {InitOptions, Model as OriginModel, ModelAttributes, FindOptions, BuildOptions} from 'sequelize';
22
import {capitalize} from '../../shared/string';
33
import {inferAlias} from '../../associations/alias-inference/alias-inference-service';
44
import {ModelNotInitializedError} from '../shared/model-not-initialized-error';
@@ -24,7 +24,7 @@ export abstract class Model<T = any, T2 = any> extends OriginModel<T, T2> {
2424

2525
static isInitialized = false;
2626

27-
static init(attributes: ModelAttributes, options: InitOptions): void {
27+
static init(attributes: ModelAttributes, options: InitOptions): Model {
2828
this.isInitialized = true;
2929
// @ts-ignore
3030
return super.init(attributes, options);
@@ -135,7 +135,7 @@ function isFunctionMember(propertyKey: string, target: any): boolean {
135135

136136
function isForbiddenMember(propertyKey: string): boolean {
137137
const FORBIDDEN_KEYS = ['name', 'constructor', 'length', 'prototype', 'caller', 'arguments', 'apply',
138-
'QueryInterface', 'QueryGenerator', 'init', 'replaceHookAliases', 'refreshAttributes', 'inspect'];
138+
'queryInterface', 'queryGenerator', 'init', 'replaceHookAliases', 'refreshAttributes', 'inspect'];
139139
return FORBIDDEN_KEYS.indexOf(propertyKey) !== -1;
140140
}
141141

test/specs/association.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import {expect, use} from 'chai';
44
import * as chaiAsPromised from 'chai-as-promised';
55
import * as OriginSequelize from 'sequelize';
6-
import * as Promise from 'bluebird';
76
import {createSequelize} from "../utils/sequelize";
87
import {
98
Sequelize, Model, Table, Column, BelongsToMany,

test/specs/instance-methods.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {expect} from 'chai';
2-
import * as Promise from 'bluebird';
32
import {Model, Table, Column} from "../../src";
43
import {createSequelize} from "../utils/sequelize";
54

test/specs/instance.spec.ts

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as Promise from 'bluebird';
1+
22
import { expect, use } from 'chai';
33
import * as chaiAsPromised from 'chai-as-promised';
44
import { useFakeTimers } from 'sinon';
@@ -656,13 +656,16 @@ describe('instance', () => {
656656
.create({aNumber: 1, bNumber: 1})
657657
// TODO Sequelize typings issue caused by sequelize/types/lib/model.d.ts on line 2394
658658
// TODO The order of overloads is wrong
659-
.tap((user) => User.update({bNumber: 2}, {where: {id: user.get('id') as any}}))
659+
.then((user) => {
660+
User.update({bNumber: 2}, {where: {id: user.get('id') as any}})
661+
return user;
662+
})
660663
.then((user) => user.reload({attributes: ['bNumber']}))
661664
.then((user) => {
662665
expect(user.get('aNumber')).to.equal(1);
663666
expect(user.get('bNumber')).to.equal(2);
664667
})
665-
);
668+
); // taps are no more supported
666669

667670
it('should update read only attributes as well (updatedAt)', () => {
668671
let _originalUser;
@@ -777,7 +780,8 @@ describe('instance', () => {
777780
})
778781
.then((lePlayer: Player) => {
779782
expect(lePlayer.shoe).not.to.be.null;
780-
return lePlayer.shoe.destroy().return(lePlayer);
783+
lePlayer.shoe.destroy(); // Destroy Now Returns Void So can't call return() void
784+
return lePlayer;
781785
})
782786
.then((lePlayer) => lePlayer.reload() as any)
783787
.then((lePlayer: Player) => {
@@ -808,8 +812,9 @@ describe('instance', () => {
808812
return leTeam.players[1]
809813
.destroy()
810814
.then(() => {
811-
return leTeam.players[0].destroy();
812-
}).return(leTeam);
815+
leTeam.players[0].destroy();
816+
return leTeam; // Destroy Return type is Void
817+
})
813818
})
814819
.then((leTeam) => leTeam.reload() as any)
815820
.then((leTeam: Team) => {
@@ -836,7 +841,8 @@ describe('instance', () => {
836841
})
837842
.then((leTeam: Team) => {
838843
expect(leTeam.players).to.have.length(2);
839-
return leTeam.players[0].destroy().then(() => leTeam as Team);
844+
leTeam.players[0].destroy(); // Since destroy return void now
845+
return leTeam;
840846
})
841847
.then((leTeam) => leTeam.reload() as any)
842848
.then((leTeam: Team) => {
@@ -1665,16 +1671,16 @@ describe('instance', () => {
16651671

16661672
it('saves many objects that each a have collection of eagerly loaded objects', () =>
16671673

1668-
Promise
1669-
.props({
1670-
bart: UserEager.create({username: 'bart', age: 20}),
1671-
lisa: UserEager.create({username: 'lisa', age: 20}),
1672-
detention1: ProjectEager.create({title: 'detention1', overdueDays: 0}),
1673-
detention2: ProjectEager.create({title: 'detention2', overdueDays: 0}),
1674-
exam1: ProjectEager.create({title: 'exam1', overdueDays: 0}),
1675-
exam2: ProjectEager.create({title: 'exam2', overdueDays: 0})
1676-
})
1677-
.then(({bart, lisa, detention1, detention2, exam1, exam2}) =>
1674+
Promise // Converting to native es6 promises
1675+
.all([
1676+
UserEager.create({username: 'bart', age: 20}),
1677+
UserEager.create({username: 'lisa', age: 20}),
1678+
ProjectEager.create({title: 'detention1', overdueDays: 0}),
1679+
ProjectEager.create({title: 'detention2', overdueDays: 0}),
1680+
ProjectEager.create({title: 'exam1', overdueDays: 0}),
1681+
ProjectEager.create({title: 'exam2', overdueDays: 0})
1682+
])
1683+
.then(([bart, lisa, detention1, detention2, exam1, exam2]) =>
16781684
Promise
16791685
.all([
16801686
bart.$set('projects', [detention1, detention2]),
@@ -2414,10 +2420,11 @@ describe('instance', () => {
24142420

24152421
it('returns an error if the model is not paranoid', () =>
24162422

2417-
User.create({username: 'Peter'}).then((user) =>
2418-
expect(() => user.restore()).to.throw(Error, 'Model is not paranoid')
2419-
)
2420-
);
2423+
User.create({username: 'Peter'}).then((user) =>user.restore()).
2424+
catch(error=>
2425+
expect(error.message).to.equal('Model is not paranoid')
2426+
)
2427+
);// Native Promises
24212428

24222429
it('restores a previously deleted model', () => {
24232430

test/specs/model-methods.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {expect} from 'chai';
2-
import * as Promise from 'bluebird';
32
import {Model, Table, Column} from "../../src";
43
import {createSequelize} from "../utils/sequelize";
54

test/specs/model.spec.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {useFakeTimers, stub, spy} from 'sinon';
55
import * as sinonChai from 'sinon-chai';
66
import * as _ from 'lodash';
77
import * as moment from 'moment';
8-
import * as Promise from 'bluebird';
98
import {Op, UniqueConstraintError} from 'sequelize';
109
import * as chaiAsPromised from 'chai-as-promised';
1110
import {createSequelize} from "../utils/sequelize";
@@ -453,9 +452,10 @@ describe('model', () => {
453452
return Promise.all([
454453
User.create({username: 'tobi', email: '[email protected]'}),
455454
User.create({username: 'tobi', email: '[email protected]'})]);
456-
}).catch(UniqueConstraintError, (err) => {
455+
}) .catch( (err) => {
457456
expect(err.message).to.equal('User and email must be unique');
458-
});
457+
});// Native Catch expect one parameter only
458+
459459
});
460460

461461
// If you use migrations to create unique indexes that have explicit names and/or contain fields
@@ -509,9 +509,10 @@ describe('model', () => {
509509
return Promise.all([
510510
User.create({userId: 1, email: '[email protected]'}),
511511
User.create({userId: 1, email: '[email protected]'})]);
512-
}).catch(UniqueConstraintError, (err) => {
512+
}).catch( (err) => {
513513
expect(err.message).to.equal('User and email must be unique');
514-
});
514+
});// Native Catch expect one parameter only
515+
515516
});
516517

517518
it('should allow the user to specify indexes in options', () => {

0 commit comments

Comments
 (0)