matissjanis / knex-serverless-mysql Goto Github PK
View Code? Open in Web Editor NEWKnex.js dialect for serverless-mysql
License: MIT License
Knex.js dialect for serverless-mysql
License: MIT License
Hi @MatissJanis
I'm trying to do a similar thing for the serverless-postgres package, is it just a case of adapting the dialect to suit?
Cheers,
Ross
Firstly, thanks a lot for this plugin!
I tried it, and I think, the plugin should use default knex methods to close the connection. Right now calling knex.destroy()
does nothing, and the connection hangs.
I've come up with this code to close the connection:
const mysql = require('serverless-mysql')({ config });
const knexServerlessMysql = require('knex-serverless-mysql');
const knexInstance = Knex({
mysql,
client: knexServerlessMysql,
} as any);
// ...
const originalDestroy = (knexInstance as any).context.destroy;
(knexInstance as any).context.destroy = async () => {
if (knexInstance) {
await originalDestroy.apply(knexInstance);
}
if (mysql) {
await mysql.end();
mysql.quit();
}
};
Is there any way this could be integrated within knex-serverless-mysql
?
I used knex-serverless-mysql
package for aws lambda.
But this error raised.
ERROR TypeError: Cannot read property 'end' of undefined at ServerlessMysqlClient.releaseConnection (/var/task/node_modules/knex-serverless-mysql
How to solve this problem?
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-call */
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
// import knex, { Knex } from 'knex';
const Knex = require('knex');
const knexServerlessMysql = require('knex-serverless-mysql');
const env = process.env.NODE_ENV || 'test';
import { Knex as knexType } from 'knex';
import config from '../../knexfile';
console.log(`env ${env}`);
export let k: knexType;
let mysql: any;
console.log(`config ${JSON.stringify(config[env])}`);
if (env === 'test' || env === 'local' || env === 'local_to_dev') {
k = Knex(config[env]);
} else if (env === 'production' || env === 'dev') {
mysql = require('serverless-mysql')({
config: {
host: process.env.DB_END_POINT,
database: process.env.DB_DATABASE,
user: process.env.DB_USERNAME,
password: process.env.DB_PASSWORD,
},
});
console.log(mysql);
k = Knex({
client: knexServerlessMysql,
connection: mysql,
});
}
void (async () => {
if (mysql) {
await mysql.end();
mysql.quit();
}
})();
console.log('db connected');
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.