Skip to content

Commit

Permalink
Require consumer code to instantiate database connections themselves
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenvelozo committed Aug 13, 2018
1 parent 31b2f94 commit f1ff57f
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 16 deletions.
16 changes: 16 additions & 0 deletions README.md
Expand Up @@ -43,6 +43,22 @@ var databaseSettings = {

var fable = require('fable').new();

// Create a MySQL connection pool (assuming MySQL is the provider you are using)
var libMySQL = require('mysql2');
fable.MeadowMySQLConnectionPool = libMySQL.createPool
(
{
connectionLimit: _Fable.settings.MySQL.ConnectionPoolLimit,
host: _Fable.settings.MySQL.Server,
port: _Fable.settings.MySQL.Port,
user: _Fable.settings.MySQL.User,
password: _Fable.settings.MySQL.Password,
database: _Fable.settings.MySQL.Database,
namedPlaceholders: true
}
);


// Create a new meadow DAL object for the "Customers" data set
var meadow = require('meadow').new(fable, 'Customers')
.setProvider('MySQL')
Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -28,18 +28,18 @@
"devDependencies": {
"chai": "3.5.0",
"codeclimate-test-reporter": "0.4.1",
"alasql": "^0.4.0",
"mysql2": "1.2.0",
"coveralls": "2.13.1",
"groc": "^0.8.0",
"istanbul": "0.4.5",
"mocha": "3.4.1"
},
"dependencies": {
"alasql": "^0.4.0",
"async": "2.4.0",
"fable": "~1.0.1",
"foxhound": "~1.0.20",
"is-my-json-valid": "2.16.0",
"mysql2": "1.2.0",
"underscore": "1.8.3"
}
}
5 changes: 3 additions & 2 deletions source/providers/Meadow-Provider-ALASQL.js
Expand Up @@ -22,8 +22,9 @@ var MeadowProvider = function()

if (!_Fable.hasOwnProperty('ALASQL'))
{
// Initialize the ALASQL driver for this fable instance.
_Fable.ALASQL = require('alasql');
// This is going to be problematic.
_Fable.log.fatal('Meadow is trying to perform queries without a valid [Fable.ALASQL] object. See the documentation for how to initialize one.');
return false;
}

var libALASQL = _Fable.ALASQL;
Expand Down
16 changes: 4 additions & 12 deletions source/providers/Meadow-Provider-MySQL.js
Expand Up @@ -29,19 +29,11 @@ var MeadowProvider = function()
{
if (typeof(_Fable.MeadowMySQLConnectionPool) !== 'object')
{
_Fable.MeadowMySQLConnectionPool = libMySQL.createPool
(
{
connectionLimit: _Fable.settings.MySQL.ConnectionPoolLimit,
host: _Fable.settings.MySQL.Server,
port: _Fable.settings.MySQL.Port,
user: _Fable.settings.MySQL.User,
password: _Fable.settings.MySQL.Password,
database: _Fable.settings.MySQL.Database,
namedPlaceholders: true
}
);
// This is going to be problematic.
_Fable.log.fatal('Meadow is trying to perform queries without a valid [Fable.MeadowMySQLConnectionPool] object. See the documentation for how to initialize one.');
return false;
}

return _Fable.MeadowMySQLConnectionPool;
};

Expand Down
3 changes: 3 additions & 0 deletions test/Meadow-Provider-ALASQL.js
Expand Up @@ -13,6 +13,7 @@ var Expect = Chai.expect;
var Assert = Chai.assert;

var libAsync = require('async');
var libALASQL = require('alasql');

var libFable = require('fable').new({
LogStreams:
Expand All @@ -28,6 +29,8 @@ var libFable = require('fable').new({
]
});

libFable.ALASQL = libALASQL;

var _AnimalJsonSchema = (
{
title: "Animal",
Expand Down
14 changes: 14 additions & 0 deletions test/Meadow-Provider-MySQL_tests.js
Expand Up @@ -42,6 +42,20 @@ var tmpFableSettings = (

var libFable = require('fable').new(tmpFableSettings);

libFable.MeadowMySQLConnectionPool = libMySQL.createPool
(
{
connectionLimit: libFable.settings.MySQL.ConnectionPoolLimit,
host: libFable.settings.MySQL.Server,
port: libFable.settings.MySQL.Port,
user: libFable.settings.MySQL.User,
password: libFable.settings.MySQL.Password,
database: libFable.settings.MySQL.Database,
namedPlaceholders: true
}
);


var _AnimalJsonSchema = (
{
title: "Animal",
Expand Down

0 comments on commit f1ff57f

Please sign in to comment.