Skip to content

Commit a11fd90

Browse files
authored
Upgrade support to Sequelize v6 (#41)
1 parent 5512447 commit a11fd90

8 files changed

Lines changed: 49 additions & 65 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Thanks in advance ❤️
1616

1717
## Compatibility
1818

19-
Compatible with hapi.js version `19.x` and sequelize `5.x`.
19+
Compatible with hapi.js version `19.x` and sequelize `6.x`.
2020

2121
Check the [releases page](https://github.com/valtlfelipe/hapi-sequelizejs/releases) for the changelog.
2222

lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ async function configure(options) {
5858
let db = null;
5959
if (options.models) {
6060
const files = await Models.getFiles(options.models, options.ignoredModels);
61-
let models = await Models.load(files, options.sequelize.import.bind(options.sequelize));
61+
let models = await Models.load(files, options.sequelize);
6262
models = await Models.applyRelations(models);
6363

6464
if (options.sync) {

lib/models.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ async function getFiles(paths, ignored) {
2828
}, []);
2929
}
3030

31-
async function load(files, fn) {
31+
async function load(files, sequelize) {
3232
if (!files) {
3333
return [];
3434
}
@@ -40,7 +40,7 @@ async function load(files, fn) {
4040
return files.reduce((acc, file) => {
4141
const models = {};
4242
const filepath = Path.isAbsolute(file) ? file : Path.join(process.cwd(), file);
43-
const Model = fn(filepath);
43+
const Model = require(filepath)(sequelize, sequelize.Sequelize.DataTypes);
4444
models[Model.name] = Model;
4545
return Object.assign({}, acc, models);
4646
}, {});

package-lock.json

Lines changed: 36 additions & 52 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hapi-sequelizejs",
3-
"version": "4.1.0",
3+
"version": "4.1.1",
44
"description": "hapi.js plugin for the Sequelize ORM",
55
"main": "lib/index.js",
66
"files": [
@@ -50,15 +50,15 @@
5050
"license": "MIT",
5151
"devDependencies": {
5252
"@hapi/code": "^8.0.1",
53+
"@hapi/hapi": "^19.1.1",
54+
"@hapi/lab": "^22.0.4",
5355
"coveralls": "^3.1.0",
5456
"eslint": "^7.1.0",
55-
"@hapi/hapi": "^19.1.1",
5657
"husky": "^4.2.5",
57-
"@hapi/lab": "^22.0.4",
5858
"lint-staged": "^10.2.8",
5959
"mysql2": "^2.1.0",
6060
"prettier": "^2.0.5",
61-
"sequelize": "^5.21.5",
61+
"sequelize": "^6.1.0",
6262
"sqlite3": "^4.2.0"
6363
},
6464
"peerDependencies": {
@@ -70,9 +70,9 @@
7070
"npm": ">=5.6.0"
7171
},
7272
"dependencies": {
73-
"glob": "7.1.6",
7473
"@hapi/hoek": "9.0.4",
75-
"@hapi/joi": "17.1.1"
74+
"@hapi/joi": "17.1.1",
75+
"glob": "7.1.6"
7676
},
7777
"funding": {
7878
"type": "individual",

test/models/shop/product/category.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// return Category model as a function to sequelize.import()
1+
// return Category model as a function
22

33
module.exports = function (sequelize, DataTypes) {
44
const Category = sequelize.define('Category', {

test/models/shop/product/product.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// return Product model as a function to sequelize.import()
1+
// return Product model as a function
22

33
module.exports = function (sequelize, DataTypes) {
44
const Product = sequelize.define('Product', {

test/models/user.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// return User model as a function to sequelize.import()
1+
// return User model as a function
22

33
module.exports = function (sequelize, DataTypes) {
44
return sequelize.define('User', {

0 commit comments

Comments
 (0)