This commit is contained in:
Tben 2023-08-29 08:02:21 +01:00
parent d8dddd5979
commit 9c61e83166
4 changed files with 27 additions and 1 deletions

View File

@ -89,6 +89,22 @@ async function addDbEntry({ dbFullName, tableName, data, tableSchema, duplicateC
console.log("DSQL: Encrypted value =>", value); console.log("DSQL: Encrypted value =>", value);
} }
if (targetFieldSchema?.pattern) {
const pattern = new RegExp(targetFieldSchema.pattern, targetFieldSchema.patternFlags || "");
if (!pattern.test(value)) {
console.log("DSQL: Pattern not matched =>", value);
value = "";
}
}
if (typeof value === "string" && !value.match(/./i)) {
value = {
toSqlString: function () {
return "NULL";
},
};
}
insertKeysArray.push("`" + dataKey + "`"); insertKeysArray.push("`" + dataKey + "`");
if (typeof value === "object") { if (typeof value === "object") {

View File

@ -81,6 +81,14 @@ async function updateDbEntry({ dbContext, paradigm, dbFullName, tableName, data,
}; };
} }
if (targetFieldSchema?.pattern) {
const pattern = new RegExp(targetFieldSchema.pattern, targetFieldSchema.patternFlags || "");
if (!pattern.test(value)) {
console.log("DSQL: Pattern not matched =>", value);
value = "";
}
}
if (typeof value === "string" && !value.match(/./i)) { if (typeof value === "string" && !value.match(/./i)) {
value = { value = {
toSqlString: function () { toSqlString: function () {

View File

@ -1,6 +1,6 @@
{ {
"name": "datasquirel", "name": "datasquirel",
"version": "1.8.8", "version": "1.8.9",
"description": "Cloud-based SQL data management tool", "description": "Cloud-based SQL data management tool",
"main": "index.js", "main": "index.js",
"bin": { "bin": {

View File

@ -60,6 +60,8 @@
* @property {string} [defaultValueLiteral] - SQL key word which generates value automatically => "CURRENT_TIMESTAMP" * @property {string} [defaultValueLiteral] - SQL key word which generates value automatically => "CURRENT_TIMESTAMP"
* @property {DSQL_ForeignKeyType} [foreignKey] - Field foreign key reference object * @property {DSQL_ForeignKeyType} [foreignKey] - Field foreign key reference object
* @property {boolean} [richText] - Rich text field * @property {boolean} [richText] - Rich text field
* @property {string | RegExp} [pattern] - Field pattern for validation. Can be a string or a regular expression. Example: "^[a-zA-Z0-9_]*$"
* @property {string} [patternFlags] - Field pattern flags for validation. Example: "i"
*/ */
/** /**