-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support sql common changes for juttle5
- Loading branch information
Vladimir Bukhin
committed
Feb 24, 2016
1 parent
8dc20c0
commit f98d379
Showing
9 changed files
with
105 additions
and
72 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
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 |
---|---|---|
@@ -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'); |
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,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; |
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,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; |
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,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; |
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,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; |
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