-
Notifications
You must be signed in to change notification settings - Fork 33
/
index.js
28 lines (24 loc) · 855 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
var ConnectionPool = require('any-db-pool')
var parseDbUrl = require('parse-db-url')
Object.defineProperty(exports, 'adapters', {
get: function () {
throw new Error(
"Replace require('any-db').adapters.<blah> with require('any-db-<blah>')"
)
}
})
exports.createConnection = function connect (dbUrl, callback) {
var adapterConfig = parseDbUrl(dbUrl)
var adapter = getAdapter(adapterConfig.adapter)
var conn = adapter.createConnection(adapterConfig, callback);
return conn
}
exports.createPool = function createPool (dbUrl, poolConfig) {
var adapterConfig = parseDbUrl(dbUrl);
var adapter = getAdapter(adapterConfig.adapter)
return new ConnectionPool(adapter, adapterConfig, poolConfig)
}
function getAdapter (protocol) {
var name = protocol.replace(':', '').split('+').shift()
return require('any-db-' + name)
}