Git Product home page Git Product logo

knex-serverless-mysql's People

Contributors

matissjanis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

trasherdk osedea jb-

knex-serverless-mysql's Issues

Provide a way to close the connection

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?

ERROR TypeError: Cannot read property 'end' of undefined at ServerlessMysqlClient.releaseConnection (/var/task/node_modules/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');

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.