primer cambio
This commit is contained in:
28
node_modules/promise-mysql/.github/workflows/node.js.yml
generated
vendored
Normal file
28
node_modules/promise-mysql/.github/workflows/node.js.yml
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
|
||||
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
|
||||
|
||||
name: Node.js CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [10.x, 12.x, 14.x]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
- run: npm ci
|
||||
- run: npm test
|
||||
1
node_modules/promise-mysql/.tool-versions
generated
vendored
Normal file
1
node_modules/promise-mysql/.tool-versions
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
nodejs 12.13.1
|
||||
22
node_modules/promise-mysql/LICENSE
generated
vendored
Normal file
22
node_modules/promise-mysql/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Luke Bonaccorsi
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
141
node_modules/promise-mysql/README.md
generated
vendored
Normal file
141
node_modules/promise-mysql/README.md
generated
vendored
Normal file
@@ -0,0 +1,141 @@
|
||||
Promise-mysql
|
||||
==================
|
||||
[](https://travis-ci.org/lukeb-uk/node-promise-mysql?branch=master)
|
||||
[](https://greenkeeper.io/)
|
||||
|
||||
Promise-mysql is a wrapper for [mysqljs/mysql](https://github.com/mysqljs/mysql) that wraps function calls with [Bluebird](https://github.com/petkaantonov/bluebird/) promises.
|
||||
|
||||
## API
|
||||
|
||||
### mysql.createConnection(connectionOptions)
|
||||
This will return a the promise of a [connection](#connection-object-methods) object.
|
||||
|
||||
#### Parameters
|
||||
`connectionOptions` _object_: A [connectionOptions](#connectionoptions-object) object
|
||||
|
||||
#### Return value
|
||||
A Bluebird `Promise` that resolves to a [connection](#connection-object-methods) object
|
||||
|
||||
### mysql.createPool(poolOptions)
|
||||
This will return a the promise of a [pool](#pool-object-methods) object.
|
||||
|
||||
#### Parameters
|
||||
`poolOptions` _object_: A [poolOptions](#pooloptions-object) object
|
||||
|
||||
#### Return value
|
||||
A Bluebird `Promise` that resolves to a [pool](#pool-object-methods) object
|
||||
|
||||
### mysql.createPoolCluster(poolClusterOptions)
|
||||
This will return a the promise of a [poolCluster](#poolcluster-object-methods) object.
|
||||
|
||||
#### Parameters
|
||||
`poolClusterOptions` _object_: A [poolClusterOptions](#poolclusteroptions-object) object
|
||||
|
||||
#### Return value
|
||||
A Bluebird `Promise` that resolves to a [poolCluster](#poolcluster-object-methods) object
|
||||
|
||||
### connectionOptions object
|
||||
|
||||
In addition to the [connection options in mysqljs/mysql](https://github.com/mysqljs/mysql#connection-options), promise-mysql accepts the following:
|
||||
|
||||
`returnArgumentsArray` _boolean_: If set to true then methods will return an array with the callback arguments from the underlying method (excluding the any errors) and the return value from the call.
|
||||
|
||||
`mysqlWrapper` _function_: A function that is passed the `mysql` object so that it can be wrapped with something like the [aws-xray-sdk module](https://www.npmjs.com/package/aws-xray-sdk). This function must either return the wrapped `mysql` object, return a promise of the wrapped `mysql` object or call the callback that is passed into the function.
|
||||
|
||||
`reconnect` _boolean_ (default: true): If set to true then the connection will reconnect on the `PROTOCOL_CONNECTION_LOST`, `ECONNRESET` and `PROTOCOL_ENQUEUE_AFTER_FATAL_ERROR` errors.
|
||||
|
||||
#### Function arguments
|
||||
|
||||
`mysql` _mysql object_: The mysql object
|
||||
|
||||
`callback(error, success)` _function_: A node-style callback that can be used to pass the wrapped version of the mysql object out of the wrapper function.
|
||||
|
||||
### Connection object methods
|
||||
|
||||
`connection.query`: Perform a query. See [mysqljs/mysql documentation](https://github.com/mysqljs/mysql#performing-queries)
|
||||
|
||||
`connection.queryStream`: Perform a query, but return the query object for streaming. See [mysqljs/mysql documentation](https://github.com/mysqljs/mysql#streaming-query-rows)
|
||||
|
||||
`connection.beginTransaction`: Begin a transaction. See [mysqljs/mysql documentation](https://github.com/mysqljs/mysql#transactions)
|
||||
|
||||
`connection.commit`: Commit a transaction. See [mysqljs/mysql documentation](https://github.com/mysqljs/mysql#transactions)
|
||||
|
||||
`connection.rollback`: Roll back a transaction. See [mysqljs/mysql documentation](https://github.com/mysqljs/mysql#transactions)
|
||||
|
||||
`connection.changeUser`: Change the current connected user. See [mysqljs/mysql documentation](https://github.com/mysqljs/mysql#switching-users-and-altering-connection-state)
|
||||
|
||||
`connection.ping`: Send a ping to the server. See [mysqljs/mysql documentation](https://github.com/mysqljs/mysql#ping)
|
||||
|
||||
`connection.end`: End the connection. See [mysqljs/mysql documentation](https://github.com/mysqljs/mysql#terminating-connections)
|
||||
|
||||
`connection.destroy`: Destroy the connection. See [mysqljs/mysql documentation](https://github.com/mysqljs/mysql#terminating-connections)
|
||||
|
||||
`connection.pause`: Pause a connection. See [mysqljs/mysql documentation](https://github.com/mysqljs/mysql#streaming-query-rows)
|
||||
|
||||
`connection.resume`: Resume a connection. See [mysqljs/mysql documentation](https://github.com/mysqljs/mysql#streaming-query-rows)
|
||||
|
||||
`connection.escape`: Escape query values. See [mysqljs/mysql documentation](https://github.com/mysqljs/mysql#escaping-query-values)
|
||||
|
||||
`connection.escapeId`: Escape query identifiers. See [mysqljs/mysql documentation](https://github.com/mysqljs/mysql#escaping-query-identifiers)
|
||||
|
||||
`connection.format`: Prepare a query. See [mysqljs/mysql documentation](https://github.com/mysqljs/mysql#preparing-queries)
|
||||
|
||||
`connection.on`: Add a listener to the connection object. See [mysqljs/mysql documentation](https://github.com/mysqljs/mysql) for events that may be listened for.
|
||||
|
||||
### poolOptions object
|
||||
|
||||
In addition to the [pool options in mysqljs/mysql](https://www.npmjs.com/package/mysql#pool-options), promise-mysql accepts the following:
|
||||
|
||||
`returnArgumentsArray` _boolean_: If set to true then methods will return an array with the callback arguments from the underlying method (excluding the any errors) and the return value from the call.
|
||||
|
||||
`mysqlWrapper` _function_: A function that is passed the `mysql` object so that it can be wrapped with something like the [aws-xray-sdk module](https://www.npmjs.com/package/aws-xray-sdk). This function must either return the wrapped `mysql` object, return a promise of the wrapped `mysql` object or call the callback that is passed into the function.
|
||||
|
||||
#### Function arguments
|
||||
|
||||
`mysql` _mysql object_: The mysql object
|
||||
|
||||
`callback(error, success)` _function_: A node-style callback that can be used to pass the wrapped version of the mysql object out of the wrapper function.
|
||||
|
||||
### Pool object methods
|
||||
|
||||
`pool.getConnection`: Get a [poolConnection](#poolconnection-object-methods) from the pool. See [mysqljs/mysql documentation](https://github.com/mysqljs/mysql#pooling-connections)
|
||||
|
||||
`pool.query`: Get a connection from the pool, run a query and then release it back into the pool. See [mysqljs/mysql documentation](https://github.com/mysqljs/mysql#pooling-connections)
|
||||
|
||||
`pool.end`: End all the connections in a pool. See [mysqljs/mysql documentation](https://github.com/mysqljs/mysql#closing-all-the-connections-in-a-pool)
|
||||
|
||||
`pool.escape`: Escape query values. See [mysqljs/mysql documentation](https://github.com/mysqljs/mysql#escaping-query-values)
|
||||
|
||||
`pool.escapeId`: Escape query identifiers. See [mysqljs/mysql documentation](https://github.com/mysqljs/mysql#escaping-query-identifiers)
|
||||
|
||||
`pool.on`: Add a listener to the pool object. See [mysqljs/mysql documentation](https://github.com/mysqljs/mysql#pool-events) for events that may be listened for.
|
||||
|
||||
### poolConnection object methods
|
||||
|
||||
In addition to the [methods in the connection object](#connection-object-methods), poolConnections also has the following method:
|
||||
|
||||
`poolConnection.release`: Release a connection back to the pool. See [mysqljs/mysql documentation](https://www.npmjs.com/package/mysql#pooling-connections)
|
||||
|
||||
### poolClusterOptions object
|
||||
|
||||
The options used to create a pool cluster. See [mysqljs/mysql documentation](https://www.npmjs.com/package/mysql#poolcluster-options)
|
||||
|
||||
### poolCluster object methods
|
||||
|
||||
`poolCluster.add`: Adds a pool configuration. See [mysqljs/mysql documentation](https://www.npmjs.com/package/mysql#poolcluster)
|
||||
|
||||
`poolCluster.remove`: Removes pool configurations. See [mysqljs/mysql documentation](https://www.npmjs.com/package/mysql#poolcluster)
|
||||
|
||||
`poolCluster.getConnection`: Get a [poolConnection](#poolconnection-object-methods) from the pool cluster. See [mysqljs/mysql documentation](https://www.npmjs.com/package/mysql#poolcluster)
|
||||
|
||||
`poolCluster.of`: Get a pool from the pool cluster. See [mysqljs/mysql documentation](https://www.npmjs.com/package/mysql#poolcluster)
|
||||
|
||||
`poolCluster.end`: End all the connections in a pool cluster. See [mysqljs/mysql documentation](https://github.com/mysqljs/mysql#pooling-connections)
|
||||
|
||||
`poolCluster.on`: Add a listener to the pool cluster object. See [mysqljs/mysql documentation](https://github.com/mysqljs/mysql#poolcluster) for events that may be listened for.
|
||||
|
||||
## Upgrading from v3 to v4
|
||||
The main difference is that `mysql.createPool` now returns a promise. Besides this, the API is the same and you should be able to upgrade straight to v4. The only other difference is the extra options in the [connectionOptions object](#connectionoptions-object).
|
||||
|
||||
## Upgrading from v4 to v5
|
||||
The `pool.releaseConnection` has been removed, please use `poolConnection.release` instead.
|
||||
144
node_modules/promise-mysql/index.d.ts
generated
vendored
Normal file
144
node_modules/promise-mysql/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,144 @@
|
||||
import * as mysql from 'mysql';
|
||||
import Bluebird from 'bluebird';
|
||||
|
||||
export function createConnection(connectionUri: string | ConnectionConfig): Bluebird<Connection>;
|
||||
|
||||
export function createPool(config: PoolConfig | string): Bluebird<Pool>;
|
||||
|
||||
export function createPoolCluster(config: mysql.PoolClusterConfig): Bluebird<PoolCluster>;
|
||||
|
||||
export { Types, escape, escapeId, format, raw, ConnectionOptions, PoolClusterConfig, MysqlError } from 'mysql';
|
||||
|
||||
export type mysqlModule = typeof mysql;
|
||||
|
||||
export type ArgumentsArray<T> = [data: T[], fields: mysql.FieldInfo[], query: Query<T>];
|
||||
export interface ConnectionConfig extends mysql.ConnectionConfig {
|
||||
mysqlWrapper?: (mysql: mysqlModule, callback?: (err: Error | null, success?: mysqlModule) => void) => mysqlModule | Promise<mysqlModule> | void;
|
||||
returnArgumentsArray?: boolean;
|
||||
reconnect?: boolean;
|
||||
}
|
||||
|
||||
export interface PoolConfig extends mysql.PoolConfig {
|
||||
mysqlWrapper?: (mysql: mysqlModule, callback: (err: Error | null, success?: mysqlModule) => void) => mysqlModule | Promise<mysqlModule> | void;
|
||||
returnArgumentsArray?: boolean;
|
||||
reconnect?: boolean;
|
||||
}
|
||||
|
||||
export interface QueryFunction {
|
||||
<T = any>(query: mysql.Query | string | mysql.QueryOptions): Bluebird<T>;
|
||||
|
||||
<T = any>(options: string, values?: any): Bluebird<T>;
|
||||
}
|
||||
|
||||
export interface Query<T> extends mysql.Query {
|
||||
|
||||
on(ev: 'result', callback: (row: T, index: number) => void): mysql.Query;
|
||||
|
||||
on(ev: 'error', callback: (err: mysql.MysqlError) => void): mysql.Query;
|
||||
|
||||
on(ev: 'fields', callback: (fields: mysql.FieldInfo[], index: number) => void): mysql.Query;
|
||||
|
||||
on<T = any>(ev: 'packet', callback: (packet: T) => void): mysql.Query;
|
||||
|
||||
on(ev: 'end', callback: () => void): mysql.Query;
|
||||
}
|
||||
|
||||
export class Connection {
|
||||
constructor(config: string | ConnectionConfig, _connection?: Connection);
|
||||
|
||||
query: QueryFunction;
|
||||
|
||||
beginTransaction(options?: mysql.QueryOptions): Bluebird<void>;
|
||||
|
||||
commit(options?: mysql.QueryOptions): Bluebird<void>;
|
||||
|
||||
rollback(options?: mysql.QueryOptions): Bluebird<void>;
|
||||
|
||||
changeUser(options?: mysql.ConnectionOptions): Bluebird<void>;
|
||||
|
||||
ping(options?: mysql.QueryOptions): Bluebird<void>;
|
||||
|
||||
queryStream<T = any>(options: string, values?: any): Query<T>;
|
||||
|
||||
statistics(options?: mysql.QueryOptions): Bluebird<void>;
|
||||
|
||||
end(options?: mysql.QueryOptions): Bluebird<void>;
|
||||
|
||||
destroy(): void;
|
||||
|
||||
pause(): void;
|
||||
|
||||
resume(): void;
|
||||
|
||||
escape(value: any, stringifyObjects?: boolean, timeZone?: string): string;
|
||||
|
||||
escapeId(value: string, forbidQualified?: boolean): string;
|
||||
|
||||
format(sql: string, values: any[], stringifyObjects?: boolean, timeZone?: string): string;
|
||||
|
||||
on(ev: 'error', callback: (err: mysql.MysqlError) => void): void;
|
||||
|
||||
on(ev: 'end', callback: () => void): void;
|
||||
}
|
||||
|
||||
export class PoolConnection extends Connection {
|
||||
constructor(config: ConnectionConfig, _connection?: mysql.Connection);
|
||||
|
||||
release(): any;
|
||||
}
|
||||
|
||||
export class Pool {
|
||||
constructor(config: ConnectionConfig, _pool?: mysql.Pool);
|
||||
|
||||
getConnection(): Bluebird<PoolConnection>;
|
||||
|
||||
query: QueryFunction;
|
||||
|
||||
end(options?: mysql.QueryOptions): Bluebird<void>;
|
||||
|
||||
release(options?: mysql.QueryOptions): Bluebird<void>;
|
||||
|
||||
escape(value: any, stringifyObjects?: boolean, timeZone?: string): string;
|
||||
|
||||
escapeId(value: string, forbidQualified?: boolean): string;
|
||||
|
||||
on(ev: 'connection' | 'acquire' | 'release', callback: (connection: mysql.PoolConnection) => void): mysql.Pool;
|
||||
|
||||
on(ev: 'error', callback: (err: mysql.MysqlError) => void): mysql.Pool;
|
||||
|
||||
on(ev: 'enqueue', callback: (err?: mysql.MysqlError) => void): mysql.Pool;
|
||||
|
||||
on<T = any>(ev: string, callback: (...args: T[]) => void): mysql.Pool;
|
||||
}
|
||||
|
||||
export class PoolCluster {
|
||||
constructor(config: mysql.PoolClusterConfig);
|
||||
|
||||
config: mysql.PoolClusterConfig;
|
||||
|
||||
add(config: PoolConfig): void;
|
||||
|
||||
add(id: string, config: PoolConfig): void;
|
||||
|
||||
end(): Bluebird<void>;
|
||||
|
||||
of(pattern: string, selector?: string): Pool;
|
||||
of(pattern: undefined | null | false, selector: string): Pool;
|
||||
|
||||
/**
|
||||
* remove all pools which match pattern
|
||||
*/
|
||||
remove(pattern: string): void;
|
||||
|
||||
getConnection(pattern?: string, selector?: string): Bluebird<PoolConnection>;
|
||||
|
||||
/**
|
||||
* Set handler to be run on a certain event.
|
||||
*/
|
||||
on<T = any>(ev: string, callback: (...args: T[]) => void): PoolCluster;
|
||||
|
||||
/**
|
||||
* Set handler to be run when a node is removed or goes offline.
|
||||
*/
|
||||
on(ev: 'remove' | 'offline', callback: (nodeId: string) => void): PoolCluster;
|
||||
}
|
||||
26
node_modules/promise-mysql/index.js
generated
vendored
Normal file
26
node_modules/promise-mysql/index.js
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
var Connection = require('./lib/connection.js');
|
||||
var Pool = require('./lib/pool.js');
|
||||
var PoolCluster = require('./lib/poolCluster.js');
|
||||
var mysql = require('mysql');
|
||||
|
||||
exports.createConnection = function(config){
|
||||
return new Connection(config);
|
||||
}
|
||||
|
||||
exports.createPool = function(config){
|
||||
return new Pool(config);
|
||||
}
|
||||
|
||||
exports.createPoolCluster = function(config){
|
||||
return new PoolCluster(config);
|
||||
}
|
||||
|
||||
exports.Types = mysql.Types;
|
||||
exports.escape = mysql.escape;
|
||||
exports.escapeId = mysql.escapeId;
|
||||
exports.format = mysql.format;
|
||||
exports.raw = mysql.raw;
|
||||
|
||||
exports.PoolCluster = PoolCluster;
|
||||
exports.Pool = Pool;
|
||||
exports.Connection = Connection;
|
||||
152
node_modules/promise-mysql/lib/connection.js
generated
vendored
Normal file
152
node_modules/promise-mysql/lib/connection.js
generated
vendored
Normal file
@@ -0,0 +1,152 @@
|
||||
'use strict';
|
||||
|
||||
const Promise = require(`bluebird`);
|
||||
const mysql = require(`mysql`);
|
||||
const promiseCallback = require(`./helper`).promiseCallback;
|
||||
|
||||
class connection {
|
||||
constructor(config = {}, _connection) {
|
||||
let mysqlValue = mysql;
|
||||
let mysqlWrapperCallbackPromise;
|
||||
|
||||
if (typeof config !== 'string') {
|
||||
|
||||
if (config.mysqlWrapper) {
|
||||
let callback;
|
||||
mysqlWrapperCallbackPromise = new Promise((resolve, reject) => {
|
||||
callback = (err, mysql) => {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
|
||||
return resolve(mysql);
|
||||
}
|
||||
})
|
||||
mysqlValue = config.mysqlWrapper(mysql, callback);
|
||||
config.mysqlWrapper = undefined;
|
||||
}
|
||||
|
||||
if (config.returnArgumentsArray) {
|
||||
this.returnArgumentsArray = config.returnArgumentsArray;
|
||||
config.returnArgumentsArray = undefined;
|
||||
}
|
||||
|
||||
if (config.reconnect === true || config.reconnect === undefined) {
|
||||
this.reconnect = true;
|
||||
config.reconnect = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
this.config = config;
|
||||
|
||||
return Promise.resolve(mysqlValue || mysqlWrapperCallbackPromise).then((mysql) => {
|
||||
if (_connection && this.reconnect) {
|
||||
addReconnectHandler(_connection, mysql, this.config, this.reconnect);
|
||||
} else if (!_connection) {
|
||||
_connection = connect(mysql, this.config, this.reconnect);
|
||||
}
|
||||
|
||||
return _connection;
|
||||
}).then((connection) => {
|
||||
this.connection = connection;
|
||||
|
||||
return this;
|
||||
})
|
||||
}
|
||||
|
||||
query() {
|
||||
return promiseCallback.apply(this.connection, [`query`, arguments, this.returnArgumentsArray]);
|
||||
}
|
||||
|
||||
queryStream(sql, values) {
|
||||
return this.connection.query(sql, values);
|
||||
};
|
||||
|
||||
beginTransaction() {
|
||||
return promiseCallback.apply(this.connection, [`beginTransaction`, arguments, this.returnArgumentsArray]);
|
||||
}
|
||||
|
||||
commit() {
|
||||
return promiseCallback.apply(this.connection, [`commit`, arguments, this.returnArgumentsArray]);
|
||||
}
|
||||
|
||||
rollback() {
|
||||
return promiseCallback.apply(this.connection, [`rollback`, arguments, this.returnArgumentsArray]);
|
||||
}
|
||||
|
||||
changeUser() {
|
||||
return promiseCallback.apply(this.connection, [`changeUser`, arguments, this.returnArgumentsArray]);
|
||||
}
|
||||
|
||||
ping() {
|
||||
return promiseCallback.apply(this.connection, [`ping`, arguments, this.returnArgumentsArray]);
|
||||
}
|
||||
|
||||
statistics() {
|
||||
return promiseCallback.apply(this.connection, [`statistics`, arguments, this.returnArgumentsArray]);
|
||||
}
|
||||
|
||||
end() {
|
||||
return promiseCallback.apply(this.connection, [`end`, arguments, this.returnArgumentsArray]);
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this.connection.destroy();
|
||||
}
|
||||
|
||||
pause() {
|
||||
this.connection.pause();
|
||||
}
|
||||
|
||||
resume() {
|
||||
this.connection.resume();
|
||||
}
|
||||
|
||||
escape(value) {
|
||||
return this.connection.escape(value);
|
||||
}
|
||||
|
||||
escapeId(value) {
|
||||
return this.connection.escapeId(value);
|
||||
}
|
||||
|
||||
format(sql, values) {
|
||||
return this.connection.format(sql, values);
|
||||
}
|
||||
|
||||
on(event, fn) {
|
||||
this.connection.on(event, fn);
|
||||
}
|
||||
}
|
||||
|
||||
const connect = (mysql, config, reconnect) => {
|
||||
const connection = mysql.createConnection(config);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
connection.connect((err) => {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
} else {
|
||||
if (reconnect) {
|
||||
addReconnectHandler(connection, mysql, config, reconnect);
|
||||
}
|
||||
|
||||
return resolve(connection);
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
const addReconnectHandler = (connection, mysql, config, reconnect) => {
|
||||
connection.once(`error`, (err) => {
|
||||
if(
|
||||
err.code === `PROTOCOL_CONNECTION_LOST` ||
|
||||
err.code === `ECONNRESET` ||
|
||||
err.code === `PROTOCOL_ENQUEUE_AFTER_FATAL_ERROR`
|
||||
) {
|
||||
connect(mysql, config, reconnect);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = connection;
|
||||
29
node_modules/promise-mysql/lib/helper.js
generated
vendored
Normal file
29
node_modules/promise-mysql/lib/helper.js
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
'use strict';
|
||||
|
||||
const Promise = require('bluebird');
|
||||
|
||||
module.exports = {
|
||||
promiseCallback: function(functionName, params, returnArgumentsArray = false) {
|
||||
params = Array.prototype.slice.call(params, 0);
|
||||
return new Promise((resolve, reject) => {
|
||||
params.push(function(err) {
|
||||
const args = Array.prototype.slice.call(arguments, 1);
|
||||
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
|
||||
process.nextTick(() => {
|
||||
if (returnArgumentsArray) {
|
||||
args.push(call);
|
||||
return resolve(args)
|
||||
}
|
||||
|
||||
return resolve(args[0]);
|
||||
})
|
||||
});
|
||||
|
||||
const call = this[functionName].apply(this, params);
|
||||
});
|
||||
}
|
||||
};
|
||||
77
node_modules/promise-mysql/lib/pool.js
generated
vendored
Normal file
77
node_modules/promise-mysql/lib/pool.js
generated
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
'use strict';
|
||||
|
||||
const Promise = require('bluebird');
|
||||
const mysql = require('mysql');
|
||||
const PoolConnection = require('./poolConnection.js');
|
||||
const promiseCallback = require('./helper').promiseCallback;
|
||||
|
||||
class pool {
|
||||
constructor(config = {}, _pool) {
|
||||
if (_pool) {
|
||||
this.pool = _pool;
|
||||
return this;
|
||||
}
|
||||
|
||||
let mysqlValue = mysql;
|
||||
let mysqlWrapperCallbackPromise;
|
||||
|
||||
if (config.mysqlWrapper) {
|
||||
let callback;
|
||||
mysqlWrapperCallbackPromise = new Promise((resolve, reject) => {
|
||||
callback = (err, mysql) => {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
|
||||
return resolve(mysql);
|
||||
}
|
||||
})
|
||||
mysqlValue = config.mysqlWrapper(mysql, callback);
|
||||
delete config.mysqlWrapper;
|
||||
}
|
||||
|
||||
if (config.returnArgumentsArray) {
|
||||
this.returnArgumentsArray = config.returnArgumentsArray;
|
||||
config.returnArgumentsArray = undefined;
|
||||
}
|
||||
|
||||
return Promise.resolve(mysqlValue || mysqlWrapperCallbackPromise).then((mysql) => {
|
||||
this.pool = mysql.createPool(config);
|
||||
return Promise.resolve(this);
|
||||
});
|
||||
}
|
||||
|
||||
getConnection() {
|
||||
return promiseCallback.apply(this.pool, ['getConnection', arguments])
|
||||
.then((_connection) => {
|
||||
const config = {
|
||||
returnArgumentsArray: this.returnArgumentsArray,
|
||||
reconnect: false
|
||||
};
|
||||
|
||||
return new PoolConnection(config, _connection);
|
||||
});
|
||||
}
|
||||
|
||||
query() {
|
||||
return promiseCallback.apply(this.pool, ['query', arguments, this.returnArgumentsArray]);
|
||||
}
|
||||
|
||||
end() {
|
||||
return promiseCallback.apply(this.pool, ['end', arguments, this.returnArgumentsArray]);
|
||||
}
|
||||
|
||||
escape(value) {
|
||||
return this.pool.escape(value);
|
||||
}
|
||||
|
||||
escapeId(value) {
|
||||
return this.pool.escapeId(value);
|
||||
}
|
||||
|
||||
on(event, fn) {
|
||||
this.pool.on(event, fn);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = pool;
|
||||
55
node_modules/promise-mysql/lib/poolCluster.js
generated
vendored
Normal file
55
node_modules/promise-mysql/lib/poolCluster.js
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
'use strict';
|
||||
|
||||
const Promise = require('bluebird');
|
||||
const mysql = require('mysql');
|
||||
const Pool = require('./pool');
|
||||
const PoolConnection = require('./poolConnection.js');
|
||||
const promiseCallback = require('./helper').promiseCallback;
|
||||
|
||||
class poolCluster {
|
||||
constructor(config = {}) {
|
||||
if (config.returnArgumentsArray) {
|
||||
this.returnArgumentsArray = config.returnArgumentsArray;
|
||||
config.returnArgumentsArray = undefined;
|
||||
}
|
||||
|
||||
return Promise.resolve(mysql).then((mysql) => {
|
||||
this.poolCluster = mysql.createPoolCluster(config);
|
||||
return Promise.resolve(this);
|
||||
});
|
||||
}
|
||||
|
||||
add(id, config) {
|
||||
return this.poolCluster.add(id, config);
|
||||
}
|
||||
|
||||
end() {
|
||||
return promiseCallback.apply(this.poolCluster, ['end', arguments, this.returnArgumentsArray]);
|
||||
}
|
||||
|
||||
of(pattern, selector) {
|
||||
const pool = this.poolCluster.of(pattern, selector);
|
||||
return new Pool(undefined, pool);
|
||||
}
|
||||
|
||||
remove(pattern) {
|
||||
return this.poolCluster.remove(pattern);
|
||||
}
|
||||
|
||||
getConnection() {
|
||||
return promiseCallback.apply(this.poolCluster, ['getConnection', arguments, this.returnArgumentsArray])
|
||||
.then((_connection) => {
|
||||
const config = {
|
||||
reconnect: false
|
||||
};
|
||||
|
||||
return new PoolConnection(config, _connection);
|
||||
});
|
||||
}
|
||||
|
||||
on(event, fn) {
|
||||
return this.poolCluster.on(event, fn);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = poolCluster;
|
||||
13
node_modules/promise-mysql/lib/poolConnection.js
generated
vendored
Normal file
13
node_modules/promise-mysql/lib/poolConnection.js
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
const Connection = require('./connection.js');
|
||||
|
||||
class poolConnection extends Connection {
|
||||
constructor(config, _connection) {
|
||||
super(config, _connection);
|
||||
}
|
||||
|
||||
release() {
|
||||
this.connection.release();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = poolConnection;
|
||||
52
node_modules/promise-mysql/package.json
generated
vendored
Normal file
52
node_modules/promise-mysql/package.json
generated
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
{
|
||||
"name": "promise-mysql",
|
||||
"version": "5.2.0",
|
||||
"description": "A bluebird wrapper for node-mysql",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"tap": "tap",
|
||||
"test": "tap test/*.js --100",
|
||||
"coverage": "tap test/*.js --coverage-report=html",
|
||||
"updatesnapshots": "TAP_SNAPSHOT=1 npm run test"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/lukeb-uk/node-promise-mysql.git"
|
||||
},
|
||||
"keywords": [
|
||||
"promise",
|
||||
"performance",
|
||||
"promises",
|
||||
"promises-a",
|
||||
"promises-aplus",
|
||||
"async",
|
||||
"await",
|
||||
"deferred",
|
||||
"deferreds",
|
||||
"future",
|
||||
"flow control",
|
||||
"dsl",
|
||||
"fluent interface",
|
||||
"database",
|
||||
"mysql",
|
||||
"mysql-promise",
|
||||
"bluebird",
|
||||
"q"
|
||||
],
|
||||
"author": "Luke Bonaccorsi",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/lukeb-uk/node-promise-mysql/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/mysql": "^2.15.2",
|
||||
"@types/bluebird": "^3.5.26",
|
||||
"bluebird": "^3.5.1",
|
||||
"mysql": "^2.18.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"proxyquire": "^2.0.1",
|
||||
"sinon": "^8.1.0",
|
||||
"tap": "^15.0.9"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user