Skip to content

Commit

Permalink
support sql common changes for juttle5
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladimir Bukhin committed Feb 24, 2016
1 parent 8dc20c0 commit f98d379
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 72 deletions.
8 changes: 1 addition & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
language: node_js

cache:
directories:
- node_modules

addons:
apt:
sources:
Expand All @@ -13,13 +9,11 @@ addons:

before_install:
- export CXX="g++-4.8"
- npm install juttle@>=0.4.0
- npm install juttle@^0.5.0

node_js:
- '4.2'
- '5.0'

script:
- npm test
- npm run test-coverage
- npm run check-coverage
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# Change Log
This file documents all notable changes to the juttle-sqlite-adapter. The release numbering uses [semantic versioning](http://semver.org).

## 0.5.0
Released 2016-02-24

### Major Changes
- Use new adapter API: Made compatible with Juttle 0.5.0.
- Use new allowedOptions shared logic.
- Make Filter class extending from ASTVisitor available from AdapterAPI.
- Change optimize class based on new graph changes.
- Refactor db to extend from shared db class.

## 0.4.0
Released 2016-02-18

Expand Down
62 changes: 1 addition & 61 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,61 +1 @@
/*
Juttle SQLite Adapter
*/

var _ = require('underscore');
var util = require("util");
var SqlAdapterCommon = require('juttle-sql-adapter-common');
var Knex = require('knex');

var REQUIRED_CONFIG_PROPERTIES = ['filename'];

function _assign_knex_getter() {
var db = require('juttle-sql-adapter-common/lib/db');
db.getKnex = function(singleDBConfig, options) {
options = options || {};

var conf = _.clone(singleDBConfig);
if (options.db) {
conf.filename = options.db;
}

var conn = getConnectionProperty(conf);

return Knex({
"client": "sqlite3",
"connection": conn
});
};
}

function getConnectionProperty(singleDBConfig) {
_.each(REQUIRED_CONFIG_PROPERTIES, function(prop) {
if (!singleDBConfig.hasOwnProperty(prop)) {
throw new Error('Each configuration must contain a field: ' + prop);
}
});

return {
filename: singleDBConfig.filename
};
}

function SqliteAdapter(config) {
var baseSql = SqlAdapterCommon.call(this, config);
_assign_knex_getter();

baseSql.name = 'sqlite';

_.extend(baseSql.read, {
procName: 'read-sqlite'
});

_.extend(baseSql.write, {
procName: 'write-sqlite'
});

return baseSql;
}

util.inherits(SqliteAdapter, SqlAdapterCommon);
module.exports = SqliteAdapter;
module.exports = require('./lib/sqlite-adapter');
40 changes: 40 additions & 0 deletions lib/db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
'use strict';

let _ = require('underscore');
let Knex = require('knex');

let SqlCommonDB = require('juttle-sql-adapter-common/lib/db');

let REQUIRED_CONFIG_PROPERTIES = ['filename'];

class DB extends SqlCommonDB {

static getKnex(singleDBConfig, options) {
options = options || {};

let conf = _.clone(singleDBConfig);
if (options.db) {
conf.filename = options.db;
}

let conn = this._getConnectionProperty(conf);

return Knex({
"client": "sqlite3",
"connection": conn
});
}

static _getConnectionProperty(singleDBConfig) {
_.each(REQUIRED_CONFIG_PROPERTIES, function(prop) {
if (!singleDBConfig.hasOwnProperty(prop)) {
throw new Error('Each configuration must contain a field: ' + prop);
}
});

return {
filename: singleDBConfig.filename
};
}
}
module.exports = DB;
11 changes: 11 additions & 0 deletions lib/read.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

let SqlCommonRead = require('juttle-sql-adapter-common/lib/read');
let db = require('./db');

class Read extends SqlCommonRead {
getDbConnection(options) {
return db.getDbConnection(options);
}
}
module.exports = Read;
19 changes: 19 additions & 0 deletions lib/sqlite-adapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
Juttle SQLite Adapter
*/
'use strict';

let db = require('./db');

function SqliteAdapter(config) {
db.init(config);

return {
name: 'sqlite',
read: require('./read'),
write: require('./write'),
optimizer: require('juttle-sql-adapter-common/lib/optimize')
};
}

module.exports = SqliteAdapter;
11 changes: 11 additions & 0 deletions lib/write.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

let SqlCommonWrite = require('juttle-sql-adapter-common/lib/write');
let db = require('./db');

class Write extends SqlCommonWrite {
getDbConnection(options) {
return db.getDbConnection(options);
}
}
module.exports = Write;
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"check-coverage": "istanbul check-coverage"
},
"dependencies": {
"juttle-sql-adapter-common": "^0.4.0",
"juttle-sql-adapter-common": "^0.5.0",
"knex": "^0.9.0",
"sqlite3": "^3.1.1",
"underscore": "^1.8.3"
Expand All @@ -31,6 +31,7 @@
"istanbul": "^0.4.2",
"mocha": "^2.3.4"
},
"juttleAdapterAPI": "^0.5.0",
"engines": {
"node": ">=4.2.0",
"npm": ">=2.14.7"
Expand Down
13 changes: 10 additions & 3 deletions test/conf.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
var TestUtils = require('juttle-sql-adapter-common/test/utils');

TestUtils.getAdapterClass = function () {
return require('../');
TestUtils.getDBClass = function () {
return require('../lib/db');
};
TestUtils.getAdapterName = function () {
return 'sqlite';
};
TestUtils.getAdapterConfig = function () {
return [
var conf = [
{
id: 'default',
filename: "./unit-test.sqlite"
Expand All @@ -14,5 +17,9 @@ TestUtils.getAdapterConfig = function () {
filename: "./not_dir/should_not_work/not_db.sqlite"
}
];

conf.path = './';
return conf;
};

module.exports = TestUtils;

0 comments on commit f98d379

Please sign in to comment.