Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6495 from ErisDS/db-config
Move db connection out of config
- Loading branch information
Showing
15 changed files
with
134 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
var knex = require('knex'), | ||
config = require('../../config'), | ||
dbConfig = config.database, | ||
knexInstance; | ||
|
||
function configureDriver(client) { | ||
var pg; | ||
|
||
if (client === 'pg' || client === 'postgres' || client === 'postgresql') { | ||
try { | ||
pg = require('pg'); | ||
} catch (e) { | ||
pg = require('pg.js'); | ||
} | ||
|
||
// By default PostgreSQL returns data as strings along with an OID that identifies | ||
// its type. We're setting the parser to convert OID 20 (int8) into a javascript | ||
// integer. | ||
pg.types.setTypeParser(20, function (val) { | ||
return val === null ? null : parseInt(val, 10); | ||
}); | ||
} | ||
} | ||
|
||
if (!knexInstance && dbConfig && dbConfig.client) { | ||
configureDriver(dbConfig.client); | ||
knexInstance = knex(dbConfig); | ||
} | ||
|
||
module.exports = knexInstance; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
var connection; | ||
|
||
Object.defineProperty(exports, 'knex', { | ||
enumerable: true, | ||
configurable: false, | ||
get: function get() { | ||
connection = connection || require('./connection'); | ||
return connection; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.