1.1.0 • Published 4 years ago

pool-me v1.1.0

Weekly downloads
14
License
ISC
Repository
github
Last release
4 years ago

Pool-me

We all have faced the tough times of going through callback hell created by using MySQL as a database for your project. This package aims at solving it, by providing Promise Wrappers for MySQL Pools.

Installation

Installation is done using npm install command:

$ npm install pool-me

Introduction

We assume, if you are looking for something like this, either you have started developing your application already, or you are planning to refactor your code. For both these tasks, its a pretty huge deal to entirely shift over packages, and especially to the one's that provide a small subset of important methods of the original package, i.e mysql. This is why, this package is aimed at simplicity. Just import the package, create your MySQL Pool using mysql package, and pass it to this package. All the methods are exactly the same, just with the flavour of Async/Await. Even the warnings are same ;)

Usage

This package relies heavily (entirely) on the mysql package.

Here is an example on how to use it:

var mysql = require('mysql')
var poolme = require('pool-me')

var pool = mysql.createPool({
    connectionLimit: 10,
    host: 'localhost',
    user: 'me',
    password: 'secret',
    database: 'my_db'
})

var newpool = poolme(pool)

Supported Methods

Currently the package supports some of the important methods required with Pools. The package is in active development stage, and will be updated with support for new methods supported by mysql package.

Pool Methods

Currently it supports the following pool methods:

getConnection

This is used to get a connection from the Pool. It is used to share the connection state for subsequent queries.

let con = await newpool.getConnection()

end

After using the pool, all the connections should be closed at the SQL Server level. This method is used to gracefully shut down the server.

await newpool.end()

Connection Methods

Currently it supports the following connection methods:

query

After receiving a connection from the pool, that connection should be used to execute a query.

let results = await con.query('SELECT something FROM sometable')
// OR
let results = await con.query('INSERT INTO sometable VALUES (?,?)', [value1, value2])

release

After executing the query or queries with the acquired connection, it should be returned back to the pool to be fetched again if required.

con.release()

Example

And here we present you with a working example, to help you fast-forward with the relatively small documentation ;)

var mysql = require('mysql')
var poolme = require('pool-me')

var pool = mysql.createPool({
    connectionLimit: 10,
    host: 'localhost',
    user: 'me',
    password: 'secret',
    database: 'my_db'
})

var newpool = poolme(pool)

FetchResults = async () => {
    let con = await newpool.getConnection()
    let results = await newpool.query('INSERT INTO creators VALUES (?, ?)', ['Sarthik', 'Gupta'])
    // Do something with results
    con.release()
    await newpool.end()
}

FetchResults()

Contribution

The package is in its budding stage. Refer to the github repository for all the suggestions, pull-requests, issues, everything.

1.1.0

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago