@carbonorm/carbonnode 4.0.0 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +123 -493
- package/dist/api/orm/builders/ConditionBuilder.d.ts +2 -0
- package/dist/index.cjs.js +32 -10
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +32 -10
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/sakila-db/C6.js +1 -1
- package/src/__tests__/sakila-db/C6.ts +1 -1
- package/src/__tests__/sqlBuilders.test.ts +17 -0
- package/src/api/orm/builders/ConditionBuilder.ts +27 -7
|
@@ -27,6 +27,8 @@ export declare abstract class ConditionBuilder<G extends OrmGenerics> extends Ag
|
|
|
27
27
|
private serializeOperand;
|
|
28
28
|
private isPlainArrayLiteral;
|
|
29
29
|
private isPlainObjectLiteral;
|
|
30
|
+
private resolveColumnDefinition;
|
|
31
|
+
private isJsonColumn;
|
|
30
32
|
protected serializeUpdateValue(value: any, params: any[] | Record<string, any>, contextColumn?: string): string;
|
|
31
33
|
private ensurePlainObject;
|
|
32
34
|
private resolveExistsInnerColumn;
|
package/dist/index.cjs.js
CHANGED
|
@@ -1827,8 +1827,9 @@ var ConditionBuilder = /** @class */ (function (_super) {
|
|
|
1827
1827
|
}
|
|
1828
1828
|
throw new Error('Unsupported operand type in SQL expression.');
|
|
1829
1829
|
};
|
|
1830
|
-
ConditionBuilder.prototype.isPlainArrayLiteral = function (value) {
|
|
1830
|
+
ConditionBuilder.prototype.isPlainArrayLiteral = function (value, allowColumnRefs) {
|
|
1831
1831
|
var _this = this;
|
|
1832
|
+
if (allowColumnRefs === void 0) { allowColumnRefs = false; }
|
|
1832
1833
|
if (!Array.isArray(value))
|
|
1833
1834
|
return false;
|
|
1834
1835
|
return value.every(function (item) {
|
|
@@ -1838,14 +1839,15 @@ var ConditionBuilder = /** @class */ (function (_super) {
|
|
|
1838
1839
|
if (type === 'string' || type === 'number' || type === 'boolean')
|
|
1839
1840
|
return true;
|
|
1840
1841
|
if (Array.isArray(item))
|
|
1841
|
-
return _this.isPlainArrayLiteral(item);
|
|
1842
|
+
return _this.isPlainArrayLiteral(item, allowColumnRefs);
|
|
1842
1843
|
if (item && typeof item === 'object')
|
|
1843
|
-
return _this.isPlainObjectLiteral(item);
|
|
1844
|
+
return _this.isPlainObjectLiteral(item, allowColumnRefs);
|
|
1844
1845
|
return false;
|
|
1845
1846
|
});
|
|
1846
1847
|
};
|
|
1847
|
-
ConditionBuilder.prototype.isPlainObjectLiteral = function (value) {
|
|
1848
|
+
ConditionBuilder.prototype.isPlainObjectLiteral = function (value, allowColumnRefs) {
|
|
1848
1849
|
var _this = this;
|
|
1850
|
+
if (allowColumnRefs === void 0) { allowColumnRefs = false; }
|
|
1849
1851
|
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
1850
1852
|
return false;
|
|
1851
1853
|
if (value instanceof Date)
|
|
@@ -1864,17 +1866,37 @@ var ConditionBuilder = /** @class */ (function (_super) {
|
|
|
1864
1866
|
})) {
|
|
1865
1867
|
return false;
|
|
1866
1868
|
}
|
|
1867
|
-
if (
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1869
|
+
if (!allowColumnRefs) {
|
|
1870
|
+
if (entries.some(function (_a) {
|
|
1871
|
+
var key = _a[0];
|
|
1872
|
+
return typeof key === 'string' && (_this.isColumnRef(key) || key.includes('.'));
|
|
1873
|
+
})) {
|
|
1874
|
+
return false;
|
|
1875
|
+
}
|
|
1872
1876
|
}
|
|
1873
1877
|
return true;
|
|
1874
1878
|
};
|
|
1879
|
+
ConditionBuilder.prototype.resolveColumnDefinition = function (column) {
|
|
1880
|
+
var _a, _b, _c, _d;
|
|
1881
|
+
if (!column || typeof column !== 'string' || !column.includes('.'))
|
|
1882
|
+
return undefined;
|
|
1883
|
+
var _e = column.split('.', 2), prefix = _e[0], colName = _e[1];
|
|
1884
|
+
var tableName = (_a = this.aliasMap[prefix]) !== null && _a !== void 0 ? _a : prefix;
|
|
1885
|
+
var table = (_c = (_b = this.config.C6) === null || _b === void 0 ? void 0 : _b.TABLES) === null || _c === void 0 ? void 0 : _c[tableName];
|
|
1886
|
+
if (!(table === null || table === void 0 ? void 0 : table.TYPE_VALIDATION))
|
|
1887
|
+
return undefined;
|
|
1888
|
+
return (_d = table.TYPE_VALIDATION[colName]) !== null && _d !== void 0 ? _d : table.TYPE_VALIDATION["".concat(tableName, ".").concat(colName)];
|
|
1889
|
+
};
|
|
1890
|
+
ConditionBuilder.prototype.isJsonColumn = function (column) {
|
|
1891
|
+
var columnDef = this.resolveColumnDefinition(column);
|
|
1892
|
+
var mysqlType = columnDef === null || columnDef === void 0 ? void 0 : columnDef.MYSQL_TYPE;
|
|
1893
|
+
return typeof mysqlType === 'string' && mysqlType.toLowerCase().includes('json');
|
|
1894
|
+
};
|
|
1875
1895
|
ConditionBuilder.prototype.serializeUpdateValue = function (value, params, contextColumn) {
|
|
1876
1896
|
var normalized = value instanceof Map ? Object.fromEntries(value) : value;
|
|
1877
|
-
|
|
1897
|
+
var allowColumnRefs = this.isJsonColumn(contextColumn);
|
|
1898
|
+
if (this.isPlainArrayLiteral(normalized, allowColumnRefs)
|
|
1899
|
+
|| this.isPlainObjectLiteral(normalized, allowColumnRefs)) {
|
|
1878
1900
|
return this.addParam(params, contextColumn !== null && contextColumn !== void 0 ? contextColumn : '', JSON.stringify(normalized));
|
|
1879
1901
|
}
|
|
1880
1902
|
var _a = this.serializeOperand(normalized, params, contextColumn), sql = _a.sql, isReference = _a.isReference, isExpression = _a.isExpression, isSubSelect = _a.isSubSelect;
|