jeefo-mysql
Advanced tools
Comparing version 0.0.2 to 0.0.3
48
index.js
@@ -19,2 +19,3 @@ /* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. | ||
let path = require("path"), | ||
async = require("async"), | ||
config_path = path.resolve(process.cwd(), "config"), | ||
@@ -24,8 +25,47 @@ config = require(config_path).database, | ||
let mysql_connection_instances = {}; | ||
let mysql_connections_container = {}; | ||
module.exports = table => { | ||
return mysql_connection_instances[table] || ( | ||
mysql_connection_instances[table] = mysql_connection(config) | ||
let filter = (conn, database, table, data, callback) => { | ||
let column_names = Object.keys(data); | ||
async.waterfall( | ||
[ | ||
cb => { | ||
let query = ` | ||
SELECT \`COLUMN_NAME\` FROM \`INFORMATION_SCHEMA\`.\`COLUMNS\` | ||
WHERE | ||
\`TABLE_SCHEMA\` = ? AND | ||
\`TABLE_NAME\` = ? AND | ||
\`COLUMN_NAME\` IN(?) | ||
`; | ||
conn(query, [database, table, column_names], cb); | ||
}, | ||
(columns, f, cb) => { | ||
columns = columns.map(c => c.COLUMN_NAME); | ||
let filtered_data = columns.reduce((payload, key) => { | ||
payload[key] = data[key]; | ||
return payload; | ||
}, {}); | ||
cb(null, filtered_data); | ||
} | ||
], | ||
callback | ||
); | ||
}; | ||
module.exports = table => { | ||
let connection = mysql_connections_container[table]; | ||
if (! connection) { | ||
connection = mysql_connections_container[table] = mysql_connection(config); | ||
connection.filter = (data, callback) => { | ||
filter(connection, config.database, table, data, callback); | ||
}; | ||
} | ||
return connection; | ||
}; |
{ | ||
"name": "jeefo-mysql", | ||
"version": "0.0.2", | ||
"description": "MySQL connection instances for each table. I had annoyed enough for MySQL Deadlocks.", | ||
"version": "0.0.3", | ||
"description": "Very simple MySQL connection instances for each table. I had annoyed enough for MySQL Deadlocks.", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com:je3f0o/node-jeefo-mysql.git" | ||
}, | ||
@@ -9,0 +10,0 @@ "keywords": [ |
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
3523
122
0
2
1