node-red-contrib-orm-objection
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -0,1 +1,5 @@ | ||
## 1.1.1 (2020-11-02) | ||
- Fixed database connections: there was one connection per node, but only the last one was closed. Sorry for that! | ||
## 1.1.0 (2020-10-21) | ||
@@ -2,0 +6,0 @@ |
@@ -35,3 +35,3 @@ { | ||
}, | ||
"version": "1.1.0" | ||
"version": "1.1.1" | ||
} |
@@ -12,21 +12,23 @@ module.exports = (RED) => { | ||
this.connect = async () => { | ||
this.emit('state', 'connecting'); | ||
knex = Knex({ | ||
client: 'mysql2', | ||
connection: { | ||
host: config.host, | ||
port: config.port, | ||
user: config.user, | ||
password: config.password, | ||
database: config.database, | ||
timezone : "+00:00", | ||
dateStrings: true, | ||
}, | ||
...knexSnakeCaseMappers(), | ||
}); | ||
if (!knex) { | ||
console.log("ObjectionORM: connect"); | ||
this.emit('state', 'connecting'); | ||
knex = Knex({ | ||
client: 'mysql2', | ||
connection: { | ||
host: config.host, | ||
port: config.port, | ||
user: config.user, | ||
password: config.password, | ||
database: config.database, | ||
timezone : "+00:00", | ||
dateStrings: true, | ||
}, | ||
...knexSnakeCaseMappers(), | ||
}); | ||
// Give the knex object to Objection. | ||
// Give the knex object to Objection. | ||
Model.knex(knex); | ||
} | ||
Model.knex(knex); | ||
await knex.select(knex.raw('1')); | ||
@@ -37,2 +39,3 @@ this.emit('state', 'connected'); | ||
this.on('close', async done => { | ||
console.log("ObjectionORM: close"); | ||
knex.destroy(); | ||
@@ -39,0 +42,0 @@ this.emit('state'); |
74607
120