Skip to content

Commit

Permalink
Merge pull request #3 from senecajs/snakecamel
Browse files Browse the repository at this point in the history
snake camel removal
  • Loading branch information
mihaidma committed Apr 5, 2016
2 parents 999d88c + bc0e47e commit 8165295
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 42 deletions.
81 changes: 46 additions & 35 deletions lib/query-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,65 @@

var _ = require('lodash')
var OpParser = require('./operator_parser')
var StandardQuery = require('seneca-standard-query')

function parseExtendedExpression (entp, sTypes, current_name, current_value, params, values) {
function parseComplexSelectOperator (sTypes, current_name, current_value, params, values) {
var result = {
processed: false
module.exports = function (seneca) {
var StandardQuery
seneca.ready(function () {
StandardQuery = seneca.export('standard-query/utils')
})

function parseExtendedExpression (sTypes, currentName, currentValue, params, values) {
function parseComplexSelectOperator (sTypes, currentName, currentValue, params, values) {
var result = {}

result.processed = _.every(currentValue, function (opVal, op) {
if (!OpParser[op]) {
result.err = 'This operator is not yet implemented: ' + op
return false
}
var err = OpParser[op](currentName, opVal, params, values, sTypes)
if (err) {
result.err = err
return false
}

return true
})

return result
}

for (var op in current_value) {
var op_val = current_value[op]
if (!OpParser[op]) {
result.err = 'This operator is not yet implemented: ' + op
return result
}
var err = OpParser[op](current_name, op_val, params, values, sTypes)
if (err) {
result.err = err
var result = StandardQuery.parseExpression(sTypes, currentName, currentValue, params, values)

if (!result.processed && _.isObject(currentValue)) {
result = parseComplexSelectOperator(sTypes, currentName, currentValue, params, values)
if (result.err) {
return result
}

result.processed = true
}

return result
}

var result = StandardQuery.parseExpression(entp, sTypes, current_name, current_value, params, values)
function buildQueryFromExpression (entp, queryParameters, sTypes, values) {
return StandardQuery.buildQueryFromExpressionCustom(entp, queryParameters, sTypes, values, parseExtendedExpression)
}

if (!result.processed) {
if (_.isObject(current_value)) {
result = parseComplexSelectOperator(sTypes, current_name, current_value, params, values)
if (result.err) {
return result
}
}
function selectstm (qent, q, sTypes, done) {
StandardQuery.selectstmCustom(qent, q, sTypes, buildQueryFromExpression, done)
}

return result
}
function fixPrepStatement (stm, sTypes) {
return StandardQuery.fixPrepStatement(stm, sTypes)
}

function buildQueryFromExpression (entp, query_parameters, sTypes, values) {
return StandardQuery.buildQueryFromExpressionCustom(entp, query_parameters, sTypes, values, parseExtendedExpression)
}
function selectstmOr (qent, q, sTypes) {
return StandardQuery.selectstmOr(qent, q, sTypes)
}

function selectstm (qent, q, sTypes, done) {
StandardQuery.selectstmCustom(qent, q, sTypes, buildQueryFromExpression, done)
return {
selectstm: selectstm,
fixPrepStatement: fixPrepStatement,
selectstmOr: selectstmOr
}
}

module.exports.selectstm = selectstm
module.exports.fixPrepStatement = StandardQuery.fixPrepStatement
module.exports.selectstmOr = StandardQuery.selectstmOr
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "seneca-store-query",
"version": "0.0.2",
"version": "0.0.3",
"description": "Extended query for Seneca framework stores",
"main": "store-query.js",
"license": "MIT",
Expand Down Expand Up @@ -46,7 +46,7 @@
"dependencies": {
"lodash": "3.10.1",
"node-uuid": "1.4.7",
"seneca-standard-query": "0.x.x"
"seneca-standard-query": "0.0.3"
},
"devDependencies": {
"chai": "3.5.0",
Expand All @@ -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#standardquery"
"seneca-postgres-store": "mihaidma/seneca-postgres-store#snakecamel"
}
}
8 changes: 6 additions & 2 deletions store-query.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict'

var _ = require('lodash')
var QueryBuilder = require('./lib/query-builder')

var actionRole = 'sql'
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 = {
Expand Down Expand Up @@ -75,4 +75,8 @@ module.exports = function queryBuilder (options) {
}
}
})

return {
name: name
}
}
6 changes: 4 additions & 2 deletions test/store.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ var si = Seneca({
describe('seneca-store-query tests ', function () {
before({}, function (done) {
si.use(require('seneca-postgres-store'), DBConfig)
si.use(require('..'))
si.ready(done)
si.ready(function () {
si.use(require('..'))
si.ready(done)
})
})

Shared.basictest({
Expand Down

0 comments on commit 8165295

Please sign in to comment.