From c083e8336b3b6486e2580bbd3067b6d7e0af91fc Mon Sep 17 00:00:00 2001 From: Mihai Dima Date: Mon, 18 Apr 2016 12:04:52 +0300 Subject: [PATCH 1/4] code enhancements --- lib/query-builder.js | 17 ++------- package.json | 6 ++-- store-query.js | 84 +++++++++++++++++++++++--------------------- 3 files changed, 49 insertions(+), 58 deletions(-) diff --git a/lib/query-builder.js b/lib/query-builder.js index e229822..b458d00 100644 --- a/lib/query-builder.js +++ b/lib/query-builder.js @@ -4,10 +4,7 @@ var _ = require('lodash') var OpParser = require('./operator_parser') module.exports = function (seneca) { - var StandardQuery - seneca.ready(function () { - StandardQuery = seneca.export('standard-query/utils') - }) + var StandardQuery = seneca.export('standard-query/utils') function parseExtendedExpression (sTypes, currentName, currentValue, params, values) { function parseComplexSelectOperator (sTypes, currentName, currentValue, params, values) { @@ -50,17 +47,9 @@ module.exports = function (seneca) { StandardQuery.selectstmCustom(qent, q, sTypes, buildQueryFromExpression, done) } - function fixPrepStatement (stm, sTypes) { - return StandardQuery.fixPrepStatement(stm, sTypes) - } - - function selectstmOr (qent, q, sTypes) { - return StandardQuery.selectstmOr(qent, q, sTypes) - } - return { selectstm: selectstm, - fixPrepStatement: fixPrepStatement, - selectstmOr: selectstmOr + fixPrepStatement: StandardQuery.fixPrepStatement, + selectstmOr: StandardQuery.selectstmOr } } diff --git a/package.json b/package.json index f7fe9ef..ab5f1a8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "seneca-store-query", - "version": "0.0.3", + "version": "0.0.4", "description": "Extended query for Seneca framework stores", "main": "store-query.js", "license": "MIT", @@ -46,7 +46,7 @@ "dependencies": { "lodash": "3.10.1", "node-uuid": "1.4.7", - "seneca-standard-query": "0.0.3" + "seneca-standard-query": "0.0.4" }, "devDependencies": { "chai": "3.5.0", @@ -58,6 +58,6 @@ "lab": "6.x.x", "seneca": "1.3.0", "seneca-store-test": "1.0.0", - "seneca-postgres-store": "mihaidma/seneca-postgres-store#snakecamel" + "seneca-postgres-store": "2.x.x" } } diff --git a/store-query.js b/store-query.js index a36c98b..7366743 100644 --- a/store-query.js +++ b/store-query.js @@ -6,7 +6,6 @@ var name = 'store-query' module.exports = function queryBuilder (options) { var seneca = this - var QueryBuilder = require('./lib/query-builder')(seneca, options) function specificTypes (storeName) { var sTypes = { @@ -23,57 +22,60 @@ module.exports = function queryBuilder (options) { return sTypes } - seneca.add({role: actionRole, hook: 'load'}, function (args, done) { - var qent = args.qent - var sTypes = specificTypes(args.target) - var q = _.clone(args.q) - q.limit$ = 1 + seneca.ready(function () { + var QueryBuilder = require('./lib/query-builder')(seneca, options) + seneca.add({role: actionRole, hook: 'load'}, function (args, done) { + var qent = args.qent + var sTypes = specificTypes(args.target) + var q = _.clone(args.q) + q.limit$ = 1 - QueryBuilder.selectstm(qent, q, sTypes, function (err, query) { - return done(err, {query: query}) + QueryBuilder.selectstm(qent, q, sTypes, function (err, query) { + return done(err, {query: query}) + }) }) - }) - seneca.add({role: actionRole, hook: 'list'}, function (args, done) { - var qent = args.qent - var q = args.q - var sTypes = specificTypes(args.target) + seneca.add({role: actionRole, hook: 'list'}, function (args, done) { + var qent = args.qent + var q = args.q + var sTypes = specificTypes(args.target) - buildSelectStatement(q, sTypes, function (err, query) { - return done(err, {query: query}) - }) + buildSelectStatement(q, sTypes, function (err, query) { + return done(err, {query: query}) + }) - function buildSelectStatement (q, sTypes, done) { - var query + function buildSelectStatement (q, sTypes, done) { + var query - if (_.isString(q)) { - return done(null, q) - } - else if (_.isArray(q)) { - // first element in array should be query, the other being values - if (q.length === 0) { - var errorDetails = { - message: 'Invalid query', - query: q - } - seneca.log.error('Invalid query') - return done(errorDetails) + if (_.isString(q)) { + return done(null, q) } - query = {} - query.text = QueryBuilder.fixPrepStatement(q[0], sTypes) - query.values = _.clone(q) - query.values.splice(0, 1) - return done(null, query) - } - else { - if (q.ids) { - return done(null, QueryBuilder.selectstmOr(qent, q, sTypes)) + else if (_.isArray(q)) { + // first element in array should be query, the other being values + if (q.length === 0) { + var errorDetails = { + message: 'Invalid query', + query: q + } + seneca.log.error('Invalid query') + return done(errorDetails) + } + query = {} + query.text = QueryBuilder.fixPrepStatement(q[0], sTypes) + query.values = _.clone(q) + query.values.splice(0, 1) + return done(null, query) } else { - QueryBuilder.selectstm(qent, q, sTypes, done) + if (q.ids) { + return done(null, QueryBuilder.selectstmOr(qent, q, sTypes)) + } + else { + QueryBuilder.selectstm(qent, q, sTypes, done) + } } } - } + }) }) return { From 773c3cd00abfdca0b7bcf4d68f58a5b0d22d65c6 Mon Sep 17 00:00:00 2001 From: Mihai Dima Date: Mon, 18 Apr 2016 17:55:47 +0300 Subject: [PATCH 2/4] reuse code from standard query --- lib/query-builder.js | 7 ++++++- package.json | 6 +++--- store-query.js | 35 ++--------------------------------- 3 files changed, 11 insertions(+), 37 deletions(-) diff --git a/lib/query-builder.js b/lib/query-builder.js index b458d00..6f4e866 100644 --- a/lib/query-builder.js +++ b/lib/query-builder.js @@ -47,9 +47,14 @@ module.exports = function (seneca) { StandardQuery.selectstmCustom(qent, q, sTypes, buildQueryFromExpression, done) } + function buildSelectStatement (qent, q, sTypes, done) { + return StandardQuery.buildSelectStatementCustom(qent, q, sTypes, selectstm, StandardQuery.selectstmOr, done) + } + return { selectstm: selectstm, fixPrepStatement: StandardQuery.fixPrepStatement, - selectstmOr: StandardQuery.selectstmOr + selectstmOr: StandardQuery.selectstmOr, + buildSelectStatement: buildSelectStatement } } diff --git a/package.json b/package.json index ab5f1a8..78b59b6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "seneca-store-query", - "version": "0.0.4", + "version": "0.0.5", "description": "Extended query for Seneca framework stores", "main": "store-query.js", "license": "MIT", @@ -46,7 +46,7 @@ "dependencies": { "lodash": "3.10.1", "node-uuid": "1.4.7", - "seneca-standard-query": "0.0.4" + "seneca-standard-query": "0.0.5" }, "devDependencies": { "chai": "3.5.0", @@ -56,7 +56,7 @@ "eslint-plugin-hapi": "4.x.x", "eslint-plugin-standard": "1.x.x", "lab": "6.x.x", - "seneca": "1.3.0", + "seneca": "1.x.x", "seneca-store-test": "1.0.0", "seneca-postgres-store": "2.x.x" } diff --git a/store-query.js b/store-query.js index 7366743..1dd6cd4 100644 --- a/store-query.js +++ b/store-query.js @@ -24,6 +24,7 @@ module.exports = function queryBuilder (options) { seneca.ready(function () { var QueryBuilder = require('./lib/query-builder')(seneca, options) + seneca.add({role: actionRole, hook: 'load'}, function (args, done) { var qent = args.qent var sTypes = specificTypes(args.target) @@ -40,41 +41,9 @@ module.exports = function queryBuilder (options) { var q = args.q var sTypes = specificTypes(args.target) - buildSelectStatement(q, sTypes, function (err, query) { + QueryBuilder.buildSelectStatement(qent, q, sTypes, function (err, query) { return done(err, {query: query}) }) - - function buildSelectStatement (q, sTypes, done) { - var query - - if (_.isString(q)) { - return done(null, q) - } - else if (_.isArray(q)) { - // first element in array should be query, the other being values - if (q.length === 0) { - var errorDetails = { - message: 'Invalid query', - query: q - } - seneca.log.error('Invalid query') - return done(errorDetails) - } - query = {} - query.text = QueryBuilder.fixPrepStatement(q[0], sTypes) - query.values = _.clone(q) - query.values.splice(0, 1) - return done(null, query) - } - else { - if (q.ids) { - return done(null, QueryBuilder.selectstmOr(qent, q, sTypes)) - } - else { - QueryBuilder.selectstm(qent, q, sTypes, done) - } - } - } }) }) From 795a2e38615746394bd7ea95741da77d7ea5a088 Mon Sep 17 00:00:00 2001 From: Mihai Dima Date: Tue, 19 Apr 2016 10:47:31 +0300 Subject: [PATCH 3/4] seneca lint --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 78b59b6..4b37268 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "chai": "3.5.0", "code": "1.5.x", "docco": "0.7.0", - "eslint-config-seneca": "1.x.x", + "eslint-config-seneca": "1.1.4", "eslint-plugin-hapi": "4.x.x", "eslint-plugin-standard": "1.x.x", "lab": "6.x.x", From 3882bd8187a4eed9d4959c7dadae95a47358456b Mon Sep 17 00:00:00 2001 From: Mihai Dima Date: Tue, 19 Apr 2016 10:51:40 +0300 Subject: [PATCH 4/4] put back the seneca lint --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4b37268..78b59b6 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "chai": "3.5.0", "code": "1.5.x", "docco": "0.7.0", - "eslint-config-seneca": "1.1.4", + "eslint-config-seneca": "1.x.x", "eslint-plugin-hapi": "4.x.x", "eslint-plugin-standard": "1.x.x", "lab": "6.x.x",