any-db-params
Advanced tools
Comparing version 1.0.2 to 2.3.0
29
index.js
@@ -1,26 +0,25 @@ | ||
'use strict'; | ||
'use strict' | ||
exports = module.exports = createParameterContext; | ||
exports = module.exports = createParameterContext | ||
exports.prefixed = require('./lib/prefixed'); | ||
exports.prefixed = require('./lib/prefixed') | ||
exports.adapters = {}; | ||
exports.adapters.postgres = require('./lib/postgres'); | ||
exports.adapters.mssql = require('./lib/mssql'); | ||
exports.adapters.mysql = require('./lib/mysql'); | ||
exports.adapters.sqlite3 = require('./lib/sqlite3'); | ||
exports.adapters = {} | ||
exports.adapters.postgres = require('./lib/postgres') | ||
exports.adapters.mssql = require('./lib/mssql') | ||
exports.adapters.mysql = require('./lib/mysql') | ||
exports.adapters.sqlite3 = require('./lib/sqlite3') | ||
function createParameterContext (queryable) { | ||
var anyDbAdapter = queryable.adapter; | ||
function createParameterContext(queryable) { | ||
var anyDbAdapter = queryable.adapter | ||
if (!(anyDbAdapter && anyDbAdapter.name)) { | ||
throw new TypeError('Argument must be a valid Queryable'); | ||
throw new TypeError('Argument must be a valid Queryable') | ||
} | ||
var impl = anyDbAdapter.createParamAccessor || exports.adapters[anyDbAdapter.name]; | ||
var impl = anyDbAdapter.createParamAccessor || exports.adapters[anyDbAdapter.name] | ||
if (!impl) { | ||
throw new Error('The ' + anyDbAdapter.name + ' adapter is not yet supported'); | ||
throw new Error('The ' + anyDbAdapter.name + ' adapter is not yet supported') | ||
} | ||
return impl(); | ||
return impl() | ||
} |
@@ -1,5 +0,5 @@ | ||
module.exports = function (values) { | ||
var copy = {}; | ||
for (var k in values) copy[k] = values[k]; | ||
return copy; | ||
}; | ||
module.exports = function(values) { | ||
var copy = {} | ||
for (var k in values) copy[k] = values[k] | ||
return copy | ||
} |
@@ -1,7 +0,7 @@ | ||
'use strict'; | ||
'use strict' | ||
var prefixed = require('./prefixed'); | ||
var prefixed = require('./prefixed') | ||
module.exports = function () { | ||
return prefixed('@', ''); | ||
}; | ||
module.exports = function() { | ||
return prefixed('@', '') | ||
} |
@@ -1,7 +0,7 @@ | ||
'use strict'; | ||
'use strict' | ||
var prefixed = require('./prefixed'); | ||
var prefixed = require('./prefixed') | ||
module.exports = function () { | ||
return prefixed('$', ''); | ||
}; | ||
module.exports = function() { | ||
return prefixed('$', '') | ||
} |
@@ -1,31 +0,31 @@ | ||
'use strict'; | ||
'use strict' | ||
module.exports = function () { | ||
var values = []; | ||
var names = []; | ||
module.exports = function() { | ||
var values = [] | ||
var names = [] | ||
function param (name, value) { | ||
var position = names.indexOf(name); | ||
function param(name, value) { | ||
var position = names.indexOf(name) | ||
if (arguments.length === 1) { | ||
if (position < 0) { | ||
throw new Error('Undefined parameter ' + name); | ||
throw new Error('Undefined parameter ' + name) | ||
} | ||
return '$' + (position + 1); | ||
return '$' + (position + 1) | ||
} | ||
if (position < 0) { | ||
names.push(name); | ||
return '$' + values.push(value); | ||
names.push(name) | ||
return '$' + values.push(value) | ||
} else { | ||
values[position] = value; | ||
return '$' + (position + 1); | ||
values[position] = value | ||
return '$' + (position + 1) | ||
} | ||
} | ||
param.values = function () { | ||
return values.slice(); | ||
}; | ||
param.values = function() { | ||
return values.slice() | ||
} | ||
return param; | ||
}; | ||
return param | ||
} |
@@ -1,26 +0,24 @@ | ||
'use strict'; | ||
'use strict' | ||
var copy = require('./copy'); | ||
var copy = require('./copy') | ||
module.exports = function (prefix, valuePrefix) { | ||
var values = {}; | ||
module.exports = function(prefix, valuePrefix) { | ||
var values = {} | ||
function param (name, value) { | ||
var argc = arguments.length; | ||
var name_ = valuePrefix + name; | ||
function param(name, value) { | ||
var argc = arguments.length | ||
var name_ = valuePrefix + name | ||
if (argc > 1) { | ||
values[name_] = value; | ||
values[name_] = value | ||
} else if (!(name_ in values)) { | ||
throw new Error('Undefined parameter ' + name) | ||
} | ||
else if (!(name_ in values)) { | ||
throw new Error('Undefined parameter ' + name); | ||
} | ||
return prefix + name; | ||
return prefix + name | ||
} | ||
param.values = copy.bind(null, values); | ||
param.values = copy.bind(null, values) | ||
return param; | ||
}; | ||
return param | ||
} |
@@ -1,7 +0,7 @@ | ||
'use strict'; | ||
'use strict' | ||
var prefixed = require('./prefixed'); | ||
var prefixed = require('./prefixed') | ||
module.exports = function () { | ||
return prefixed('$', '$'); | ||
}; | ||
module.exports = function() { | ||
return prefixed('$', '$') | ||
} |
{ | ||
"name": "any-db-params", | ||
"version": "1.0.2", | ||
"version": "2.3.0", | ||
"description": "Collect parameters and generate SQL placeholders for any database", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
5164
81