Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mihaidma committed Apr 5, 2016
1 parent 5df5151 commit bc0e47e
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions lib/query-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,47 @@
var _ = require('lodash')
var OpParser = require('./operator_parser')

module.exports = function (seneca, opts) {
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 = {
processed: false
}
var result = {}

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

result.processed = true
}
return true
})

return result
}

var result = StandardQuery.parseExpression(sTypes, currentName, currentValue, params, values)

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

return result
}

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

function selectstm (qent, q, sTypes, done) {
Expand Down

0 comments on commit bc0e47e

Please sign in to comment.