@soinlabs/db
Advanced tools
Comparing version 1.1.0-alpha.56 to 1.1.0-alpha.58
@@ -364,26 +364,60 @@ /* eslint-disable no-await-in-loop */ | ||
case Op.in: | ||
// TODO: Manage null inside array | ||
queries.push({ | ||
condition: `${tableName}${parentKey} IN (:...${parentKey}${paramNumber})`, | ||
params: { | ||
[`${parentKey}${paramNumber++}`]: meta.columns[parentKey] | ||
.transformer | ||
? meta.columns[parentKey].transformer.to(value) | ||
: value, | ||
}, | ||
}) | ||
case Op.in: { | ||
const newValue = meta.columns[parentKey].transformer | ||
? meta.columns[parentKey].transformer.to(value) | ||
: value | ||
if (newValue.includes(null)) { | ||
if (newValue.length > 1) { | ||
queries.push({ | ||
condition: `${tableName}${parentKey} IN (:...${parentKey}${paramNumber}) OR ${tableName}${parentKey} IS NULL`, | ||
params: { | ||
[`${parentKey}${paramNumber++}`]: newValue.filter( | ||
x => x !== null | ||
), | ||
}, | ||
}) | ||
} else { | ||
queries.push({ | ||
condition: `${tableName}${parentKey} IS NULL`, | ||
}) | ||
} | ||
} else { | ||
queries.push({ | ||
condition: `${tableName}${parentKey} IN (:...${parentKey}${paramNumber})`, | ||
params: { | ||
[`${parentKey}${paramNumber++}`]: newValue, | ||
}, | ||
}) | ||
} | ||
break | ||
case Op.notIn: | ||
queries.push({ | ||
condition: `${tableName}${parentKey} NOT IN (:...${parentKey}${paramNumber})`, | ||
params: { | ||
[`${parentKey}${paramNumber++}`]: meta.columns[parentKey] | ||
.transformer | ||
? meta.columns[parentKey].transformer.to(value) | ||
: value, | ||
}, | ||
}) | ||
} | ||
case Op.notIn: { | ||
const newValue = meta.columns[parentKey].transformer | ||
? meta.columns[parentKey].transformer.to(value) | ||
: value | ||
if (newValue.includes(null)) { | ||
if (newValue.length > 1) { | ||
queries.push({ | ||
condition: `${tableName}${parentKey} NOT IN (:...${parentKey}${paramNumber}) OR ${tableName}${parentKey} IS NOT NULL`, | ||
params: { | ||
[`${parentKey}${paramNumber++}`]: newValue.filter( | ||
x => x !== null | ||
), | ||
}, | ||
}) | ||
} else { | ||
queries.push({ | ||
condition: `${tableName}${parentKey} IS NOT NULL`, | ||
}) | ||
} | ||
} else { | ||
queries.push({ | ||
condition: `${tableName}${parentKey} NOT IN (:...${parentKey}${paramNumber})`, | ||
params: { | ||
[`${parentKey}${paramNumber++}`]: newValue, | ||
}, | ||
}) | ||
} | ||
break | ||
} | ||
case Op.between: | ||
@@ -468,6 +502,5 @@ // TODO: Between check array of 2 elements | ||
case Op.or: { | ||
// TODO: OR interno | ||
const heapStart = queries.length | ||
for (const elem of value) { | ||
buildQueriesInternal(null, elem) | ||
buildQueriesInternal(parentKey, elem) | ||
} | ||
@@ -522,11 +555,28 @@ const heapEnd = queries.length | ||
if (parentKey === null) { | ||
// TODO: Manage null inside array | ||
queries.push({ | ||
condition: `${tableName}${key} IN (:...${key}${paramNumber})`, | ||
params: { | ||
[`${key}${paramNumber++}`]: meta.columns[key].transformer | ||
? meta.columns[key].transformer.to(value) | ||
: value, | ||
}, | ||
}) | ||
const newValue = meta.columns[key].transformer | ||
? meta.columns[key].transformer.to(value) | ||
: value | ||
if (newValue.includes(null)) { | ||
if (newValue.length > 1) { | ||
queries.push({ | ||
condition: `${tableName}${key} IN (:...${key}${paramNumber}) OR ${tableName}${key} IS NULL`, | ||
params: { | ||
[`${key}${paramNumber++}`]: newValue.filter( | ||
x => x !== null | ||
), | ||
}, | ||
}) | ||
} else { | ||
queries.push({ | ||
condition: `${tableName}${key} IS NULL`, | ||
}) | ||
} | ||
} else { | ||
queries.push({ | ||
condition: `${tableName}${key} IN (:...${key}${paramNumber})`, | ||
params: { | ||
[`${key}${paramNumber++}`]: newValue, | ||
}, | ||
}) | ||
} | ||
} else { | ||
@@ -533,0 +583,0 @@ // TODO: in reality it shouldn't enter here |
{ | ||
"name": "@soinlabs/db", | ||
"version": "1.1.0-alpha.56", | ||
"version": "1.1.0-alpha.58", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "repository": "", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
223163
7079