Socket
Socket
Sign inDemoInstall

knex-serverless-mysql

Package Overview
Dependencies
26
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    knex-serverless-mysql

Knex.js dialect for serverless-mysql


Version published
Weekly downloads
504
decreased by-20.63%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

knex-serverless-mysql

npm npm

Minimalistic knex.js dialect for serverless-mysql.

Motivation

serverless-mysql persists database connections across multiple AWS Lambda function execution contexts. This reduces the load on the database. However, this client is not natively supported by Knex. This library solves the problem.

Getting Started

Installation

yarn add knex-serverless-mysql

# or

npm install knex-serverless-mysql

Simple Example

const Knex = require('knex');
const knexServerlessMysql = require('knex-serverless-mysql');

const mysql = require('serverless-mysql')({
  config: {
    host     : process.env.DB_HOST,
    database : process.env.DB_DATABASE,
    user     : process.env.DB_USERNAME,
    password : process.env.DB_PASSWORD,
  },
});

const knex = Knex({
  client: knexServerlessMysql,
  mysql,
});

exports.run = function () {
  return knex('table_name').where('id', 1);
}

Usage with datasource-sql

const Knex = require('knex');
const knexServerlessMysql = require('knex-serverless-mysql');
const { SQLDataSource } = require('datasource-sql');

const mysql = require('serverless-mysql')({
  config: {
    host     : process.env.DB_HOST,
    database : process.env.DB_DATABASE,
    user     : process.env.DB_USERNAME,
    password : process.env.DB_PASSWORD,
  },
});

const knex = Knex({
  client: knexServerlessMysql,
  mysql,
});

class TableNameDataSource extends SQLDataSource {
  getRowById(id) {
    return this.knex('table_name').where('id', id);
  }
}

const dataSource = new TableNameDataSource(knex);

exports.run = function () {
  return dataSource.getRowById(1);
}

Contributing

All contributions are welcome!

Please open an issue or pull request.

FAQs

Last updated on 26 Apr 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc