mirror of
https://github.com/nocodb/nocodb.git
synced 2026-05-02 02:28:40 +00:00
Feature : xjoin API 🔥 🔥
npm v0.4.0
This commit is contained in:
@@ -78,7 +78,7 @@ function prepareBetweenValue(value) {
|
||||
}
|
||||
|
||||
|
||||
function replaceWhereParamsToQMarks(openParentheses, str, comparisonOperator) {
|
||||
function replaceWhereParamsToQMarks(openParentheses, str, comparisonOperator, condType) {
|
||||
|
||||
let converted = ''
|
||||
|
||||
@@ -93,8 +93,11 @@ function replaceWhereParamsToQMarks(openParentheses, str, comparisonOperator) {
|
||||
}
|
||||
} else {
|
||||
|
||||
if (comparisonOperator !== ' in ' && comparisonOperator !== ' between ')
|
||||
if (comparisonOperator !== ' in ' && comparisonOperator !== ' between ' && condType !== ' on ') {
|
||||
converted = '?'
|
||||
} else if (condType === ' on ') {
|
||||
converted = '??'
|
||||
}
|
||||
|
||||
for (var i = str.length - 1; i >= 0; --i) {
|
||||
if (str[i] === ')') {
|
||||
@@ -105,6 +108,7 @@ function replaceWhereParamsToQMarks(openParentheses, str, comparisonOperator) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return converted;
|
||||
}
|
||||
|
||||
@@ -215,116 +219,113 @@ exports.getConditionClause = function (whereInQueryParams, condType = 'where') {
|
||||
|
||||
if (numOfConditions && logicalOperatorsInClause && numOfConditions.length !== logicalOperatorsInClause.length + 1) {
|
||||
console.log('conditions and logical operators mismatch', numOfConditions.length, logicalOperatorsInClause.length);
|
||||
return
|
||||
}
|
||||
} else {
|
||||
//console.log('numOfConditions',numOfConditions,whereInQueryParams);
|
||||
//console.log('logicalOperatorsInClause',logicalOperatorsInClause);
|
||||
|
||||
// console.log('numOfConditions',numOfConditions,whereInQueryParams);
|
||||
// console.log('logicalOperatorsInClause',logicalOperatorsInClause);
|
||||
for (var i = 0; i < numOfConditions.length; ++i) {
|
||||
|
||||
for (var i = 0; i < numOfConditions.length; ++i) {
|
||||
let variable = ''
|
||||
let comparisonOperator = ''
|
||||
let logicalOperator = ''
|
||||
let variableValue = ''
|
||||
let temp = ''
|
||||
|
||||
let variable = ''
|
||||
let comparisonOperator = ''
|
||||
let logicalOperator = ''
|
||||
let variableValue = ''
|
||||
let temp = ''
|
||||
// split on commas
|
||||
var arr = numOfConditions[i].split(',');
|
||||
|
||||
// split on commas
|
||||
var arr = numOfConditions[i].split(',');
|
||||
// consider first two splits only
|
||||
var result = arr.splice(0, 2);
|
||||
|
||||
// consider first two splits only
|
||||
var result = arr.splice(0, 2);
|
||||
// join to make only 3 array elements
|
||||
result.push(arr.join(','));
|
||||
|
||||
// join to make only 3 array elements
|
||||
result.push(arr.join(','));
|
||||
|
||||
// variable, operator, variablevalue
|
||||
if (result.length !== 3) {
|
||||
grammarErr = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
/**************** START : variable ****************/
|
||||
//console.log(result);
|
||||
variable = result[0].match(/\(+(.*)/);
|
||||
|
||||
// console.log('variable',variable);
|
||||
|
||||
if (!variable || variable.length !== 2) {
|
||||
grammarErr = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
// get the variableName and push
|
||||
whereParams.push(variable[1])
|
||||
|
||||
// then replace the variable name with ??
|
||||
temp = replaceWhereParamsToQMarks(true, result[0])
|
||||
if (!temp) {
|
||||
grammarErr = 1;
|
||||
break;
|
||||
}
|
||||
whereQuery += temp
|
||||
|
||||
/**************** END : variable ****************/
|
||||
|
||||
|
||||
/**************** START : operator and value ****************/
|
||||
comparisonOperator = getComparisonOperator(result[1])
|
||||
if (!comparisonOperator) {
|
||||
grammarErr = 1;
|
||||
break;
|
||||
}
|
||||
whereQuery += comparisonOperator
|
||||
|
||||
// get the variableValue and push to params
|
||||
variableValue = result[2].match(/(.*?)\)/)
|
||||
if (!variableValue || variableValue.length !== 2) {
|
||||
grammarErr = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
if (comparisonOperator === ' in ') {
|
||||
let obj = prepareInClauseParams(variableValue[1])
|
||||
whereQuery += obj.whereQuery
|
||||
whereParams = whereParams.concat(obj.whereParams)
|
||||
} else if (comparisonOperator === ' like ' || comparisonOperator === ' not like ') {
|
||||
whereParams.push(prepareLikeValue(variableValue[1]))
|
||||
} else if (comparisonOperator === ' is ') {
|
||||
whereParams.push(prepareIsValue(variableValue[1]))
|
||||
} else if (comparisonOperator === ' between ') {
|
||||
let obj = prepareBetweenValue(variableValue[1])
|
||||
whereQuery += obj.whereQuery
|
||||
whereParams = whereParams.concat(obj.whereParams)
|
||||
//console.log(whereQuery, whereParams);
|
||||
} else {
|
||||
whereParams.push(variableValue[1])
|
||||
}
|
||||
|
||||
// then replace the variableValue with ?
|
||||
temp = replaceWhereParamsToQMarks(false, result[2], comparisonOperator)
|
||||
if (!temp) {
|
||||
grammarErr = 1;
|
||||
break;
|
||||
}
|
||||
whereQuery += temp
|
||||
|
||||
|
||||
// only
|
||||
if (numOfConditions.length !== -1 && i !== numOfConditions.length - 1) {
|
||||
//console.log('finding logical operator for',logicalOperatorsInClause[i]);
|
||||
logicalOperator = getLogicalOperator(logicalOperatorsInClause[i])
|
||||
|
||||
if (!logicalOperator) {
|
||||
// variable, operator, variablevalue
|
||||
if (result.length !== 3) {
|
||||
grammarErr = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
whereQuery += getLogicalOperator(logicalOperatorsInClause[i])
|
||||
/**************** START : variable ****************/
|
||||
//console.log('variable, operator, variablevalue',result);
|
||||
variable = result[0].match(/\(+(.*)/);
|
||||
|
||||
//console.log('variable',variable);
|
||||
|
||||
if (!variable || variable.length !== 2) {
|
||||
grammarErr = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
// get the variableName and push
|
||||
whereParams.push(variable[1])
|
||||
|
||||
// then replace the variable name with ??
|
||||
temp = replaceWhereParamsToQMarks(true, result[0], ' ignore ', condType)
|
||||
if (!temp) {
|
||||
grammarErr = 1;
|
||||
break;
|
||||
}
|
||||
whereQuery += temp
|
||||
|
||||
/**************** END : variable ****************/
|
||||
|
||||
|
||||
/**************** START : operator and value ****************/
|
||||
comparisonOperator = getComparisonOperator(result[1])
|
||||
if (!comparisonOperator) {
|
||||
grammarErr = 1;
|
||||
break;
|
||||
}
|
||||
whereQuery += comparisonOperator
|
||||
|
||||
// get the variableValue and push to params
|
||||
variableValue = result[2].match(/(.*?)\)/)
|
||||
if (!variableValue || variableValue.length !== 2) {
|
||||
grammarErr = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
if (comparisonOperator === ' in ') {
|
||||
let obj = prepareInClauseParams(variableValue[1])
|
||||
whereQuery += obj.whereQuery
|
||||
whereParams = whereParams.concat(obj.whereParams)
|
||||
} else if (comparisonOperator === ' like ' || comparisonOperator === ' not like ') {
|
||||
whereParams.push(prepareLikeValue(variableValue[1]))
|
||||
} else if (comparisonOperator === ' is ') {
|
||||
whereParams.push(prepareIsValue(variableValue[1]))
|
||||
} else if (comparisonOperator === ' between ') {
|
||||
let obj = prepareBetweenValue(variableValue[1])
|
||||
whereQuery += obj.whereQuery
|
||||
whereParams = whereParams.concat(obj.whereParams)
|
||||
//console.log(whereQuery, whereParams);
|
||||
} else {
|
||||
whereParams.push(variableValue[1])
|
||||
}
|
||||
|
||||
// then replace the variableValue with ?
|
||||
temp = replaceWhereParamsToQMarks(false, result[2], comparisonOperator, condType)
|
||||
if (!temp) {
|
||||
grammarErr = 1;
|
||||
break;
|
||||
}
|
||||
whereQuery += temp
|
||||
|
||||
if (numOfConditions.length !== -1 && i !== numOfConditions.length - 1) {
|
||||
//console.log('finding logical operator for',logicalOperatorsInClause[i]);
|
||||
logicalOperator = getLogicalOperator(logicalOperatorsInClause[i])
|
||||
|
||||
if (!logicalOperator) {
|
||||
grammarErr = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
whereQuery += getLogicalOperator(logicalOperatorsInClause[i])
|
||||
}
|
||||
/**************** END : operator ****************/
|
||||
|
||||
|
||||
}
|
||||
/**************** END : operator ****************/
|
||||
|
||||
|
||||
}
|
||||
|
||||
let obj = {}
|
||||
|
||||
Reference in New Issue
Block a user