2014-10-31 11:57:44 -04:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
// Load the test base
|
|
|
|
delete require.cache[require.resolve('../query-builder-base')];
|
|
|
|
var testBase = require('../query-builder-base');
|
|
|
|
var tests = testBase.tests;
|
|
|
|
|
|
|
|
// Load the test config file
|
|
|
|
var adapterName = 'dblite';
|
2014-10-31 13:15:31 -04:00
|
|
|
var sqlite = null;
|
|
|
|
var connection = null;
|
2014-10-31 11:57:44 -04:00
|
|
|
|
|
|
|
// Set up the connection
|
2014-10-31 13:15:31 -04:00
|
|
|
try {
|
|
|
|
sqlite = require(adapterName).withSQLite('3.8.6+');
|
|
|
|
connection = sqlite(':memory:');
|
|
|
|
} catch (e) {
|
|
|
|
// Export an empty testsuite if module not loaded
|
|
|
|
console.log(e);
|
|
|
|
console.log("Database adapter dblite not found");
|
|
|
|
return {};
|
|
|
|
}
|
2014-10-31 11:57:44 -04:00
|
|
|
|
2014-10-31 13:15:31 -04:00
|
|
|
if (connection)
|
|
|
|
{
|
|
|
|
// Set up the query builder object
|
|
|
|
var nodeQuery = require('../../lib/node-query');
|
2014-11-03 10:59:18 -05:00
|
|
|
var qb = nodeQuery.init('sqlite', connection, adapterName);
|
2014-10-31 11:57:44 -04:00
|
|
|
|
2014-10-31 13:15:31 -04:00
|
|
|
// Set up the sqlite database
|
|
|
|
var sql = 'CREATE TABLE IF NOT EXISTS "create_test" ("id" INTEGER PRIMARY KEY, "key" TEXT, "val" TEXT);' +
|
|
|
|
'CREATE TABLE IF NOT EXISTS "create_join" ("id" INTEGER PRIMARY KEY, "key" TEXT, "val" TEXT);';
|
|
|
|
connection.query(sql);
|
2014-10-31 11:57:44 -04:00
|
|
|
|
2014-10-31 13:15:31 -04:00
|
|
|
// Set up the test base
|
|
|
|
testBase._setUp(qb, function(test, err, rows) {
|
|
|
|
if (err != null) {
|
|
|
|
test.done();
|
|
|
|
throw new Error(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Insert/Update/Delete queries return undefined
|
|
|
|
if (rows === undefined) {
|
|
|
|
rows = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
test.ok(rows, 'dblite: Valid result for generated query');
|
2014-10-31 11:57:44 -04:00
|
|
|
test.done();
|
2014-10-31 13:15:31 -04:00
|
|
|
});
|
2014-10-31 11:57:44 -04:00
|
|
|
|
2014-10-31 13:15:31 -04:00
|
|
|
tests["dblite adapter with query builder"] = function(test) {
|
|
|
|
test.expect(1);
|
|
|
|
test.ok(testBase.qb);
|
|
|
|
|
|
|
|
// Close the db connection
|
|
|
|
connection.close();
|
|
|
|
test.done();
|
|
|
|
};
|
2014-10-31 11:57:44 -04:00
|
|
|
|
2014-10-31 13:15:31 -04:00
|
|
|
// Export the final test object
|
|
|
|
module.exports = tests;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
module.exports = {};
|
|
|
|
}
|
2014-10-31 11:57:44 -04:00
|
|
|
|
|
|
|
|
|
|
|
|