Updates
This commit is contained in:
+31
-9
@@ -72,6 +72,7 @@ function addDbEntry(_a) {
|
||||
}
|
||||
}
|
||||
function generateQuery(data) {
|
||||
var _a, _b;
|
||||
const dataKeys = Object.keys(data);
|
||||
let insertKeysArray = [];
|
||||
let insertValuesArray = [];
|
||||
@@ -79,6 +80,9 @@ function addDbEntry(_a) {
|
||||
try {
|
||||
const dataKey = dataKeys[i];
|
||||
let value = data[dataKey];
|
||||
const targetFieldSchema = tableSchema
|
||||
? (_a = tableSchema === null || tableSchema === void 0 ? void 0 : tableSchema.fields) === null || _a === void 0 ? void 0 : _a.find((field) => field.fieldName === dataKey)
|
||||
: null;
|
||||
const parsedValue = (0, grab_parsed_value_1.default)({
|
||||
dataKey,
|
||||
encryptionKey,
|
||||
@@ -89,7 +93,10 @@ function addDbEntry(_a) {
|
||||
if (typeof parsedValue == "undefined")
|
||||
continue;
|
||||
insertKeysArray.push("`" + dataKey + "`");
|
||||
if (typeof parsedValue == "number") {
|
||||
if ((_b = targetFieldSchema === null || targetFieldSchema === void 0 ? void 0 : targetFieldSchema.dataType) === null || _b === void 0 ? void 0 : _b.match(/vector/i)) {
|
||||
insertValuesArray.push(`VEC_FromText('${parsedValue}')`);
|
||||
}
|
||||
else if (typeof parsedValue == "number") {
|
||||
insertValuesArray.push(String(parsedValue));
|
||||
}
|
||||
else {
|
||||
@@ -112,16 +119,32 @@ function addDbEntry(_a) {
|
||||
const queryValuesArray = insertValuesArray;
|
||||
return { queryValuesArray, insertValuesArray, insertKeysArray };
|
||||
}
|
||||
function grabQueryValuesString(arr) {
|
||||
return arr
|
||||
.map((v, i) => {
|
||||
if (v.toString().match(/VEC_FromText/i)) {
|
||||
return v;
|
||||
}
|
||||
return "?";
|
||||
})
|
||||
.join(",");
|
||||
}
|
||||
function grabFinalQueryValuesArr(arr) {
|
||||
return arr
|
||||
.filter((v) => !v.toString().match(/VEC_FromText/i))
|
||||
.map((v) => String(v));
|
||||
}
|
||||
if (newData) {
|
||||
const { insertKeysArray, insertValuesArray, queryValuesArray } = generateQuery(newData);
|
||||
const query = `INSERT INTO ${isMaster && !dbFullName ? "" : `\`${dbFullName}\`.`}\`${tableName}\` (${insertKeysArray.join(",")}) VALUES (${insertValuesArray.map(() => "?").join(",")})`;
|
||||
const newInsert = yield (0, conn_db_handler_1.default)(null, query, queryValuesArray, debug);
|
||||
const query = `INSERT INTO ${isMaster && !dbFullName ? "" : `\`${dbFullName}\`.`}\`${tableName}\` (${insertKeysArray.join(",")}) VALUES (${grabQueryValuesString(insertValuesArray)})`;
|
||||
const finalQueryValues = grabFinalQueryValuesArr(queryValuesArray);
|
||||
const newInsert = yield (0, conn_db_handler_1.default)(null, query, finalQueryValues, debug);
|
||||
return {
|
||||
success: Boolean(newInsert === null || newInsert === void 0 ? void 0 : newInsert.insertId),
|
||||
payload: newInsert,
|
||||
queryObject: {
|
||||
sql: query,
|
||||
params: queryValuesArray,
|
||||
params: finalQueryValues,
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -139,11 +162,10 @@ function addDbEntry(_a) {
|
||||
batchQueryValuesArray.push(queryValuesArray);
|
||||
}
|
||||
const query = `INSERT INTO ${isMaster && !dbFullName ? "" : `\`${dbFullName}\`.`}\`${tableName}\` (${batchInsertKeysArray === null || batchInsertKeysArray === void 0 ? void 0 : batchInsertKeysArray.join(",")}) VALUES ${batchInsertValuesArray
|
||||
.map((vl) => `(${vl.map(() => "?").join(",")})`)
|
||||
.map((vl) => `(${grabQueryValuesString(vl)})`)
|
||||
.join(",")}`;
|
||||
console.log("query", query);
|
||||
console.log("batchQueryValuesArray", batchQueryValuesArray);
|
||||
const newInsert = yield (0, conn_db_handler_1.default)(null, query, batchQueryValuesArray.flat(), debug);
|
||||
const finalQueryValues = grabFinalQueryValuesArr(batchQueryValuesArray.flat());
|
||||
const newInsert = yield (0, conn_db_handler_1.default)(null, query, finalQueryValues, debug);
|
||||
if (debug) {
|
||||
(0, debug_log_1.default)({
|
||||
log: newInsert,
|
||||
@@ -156,7 +178,7 @@ function addDbEntry(_a) {
|
||||
payload: newInsert,
|
||||
queryObject: {
|
||||
sql: query,
|
||||
params: batchQueryValuesArray.flat(),
|
||||
params: finalQueryValues,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -14,11 +14,8 @@ const encrypt_1 = __importDefault(require("../../dsql/encrypt"));
|
||||
function grabParsedValue({ value, tableSchema, encryptionKey, encryptionSalt, dataKey, }) {
|
||||
var _a, _b;
|
||||
let newValue = value;
|
||||
const targetFieldSchemaArray = tableSchema
|
||||
? (_a = tableSchema === null || tableSchema === void 0 ? void 0 : tableSchema.fields) === null || _a === void 0 ? void 0 : _a.filter((field) => field.fieldName === dataKey)
|
||||
: null;
|
||||
const targetFieldSchema = targetFieldSchemaArray && targetFieldSchemaArray[0]
|
||||
? targetFieldSchemaArray[0]
|
||||
const targetFieldSchema = tableSchema
|
||||
? (_a = tableSchema === null || tableSchema === void 0 ? void 0 : tableSchema.fields) === null || _a === void 0 ? void 0 : _a.find((field) => field.fieldName === dataKey)
|
||||
: null;
|
||||
if (typeof newValue == "undefined")
|
||||
return;
|
||||
|
||||
+10
-1
@@ -24,6 +24,7 @@ const grab_parsed_value_1 = __importDefault(require("./grab-parsed-value"));
|
||||
*/
|
||||
function updateDbEntry(_a) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ dbContext, dbFullName, tableName, data, tableSchema, identifierColumnName, identifierValue, encryptionKey, encryptionSalt, forceLocal, debug, }) {
|
||||
var _b, _c;
|
||||
/**
|
||||
* Check if data is valid
|
||||
*/
|
||||
@@ -54,6 +55,9 @@ function updateDbEntry(_a) {
|
||||
try {
|
||||
const dataKey = dataKeys[i];
|
||||
let value = newData[dataKey];
|
||||
const targetFieldSchema = tableSchema
|
||||
? (_b = tableSchema === null || tableSchema === void 0 ? void 0 : tableSchema.fields) === null || _b === void 0 ? void 0 : _b.find((field) => field.fieldName === dataKey)
|
||||
: null;
|
||||
const parsedValue = (0, grab_parsed_value_1.default)({
|
||||
dataKey,
|
||||
encryptionKey,
|
||||
@@ -63,7 +67,12 @@ function updateDbEntry(_a) {
|
||||
});
|
||||
if (typeof parsedValue == "undefined")
|
||||
continue;
|
||||
updateKeyValueArray.push(`\`${dataKey}\`=?`);
|
||||
if ((_c = targetFieldSchema === null || targetFieldSchema === void 0 ? void 0 : targetFieldSchema.dataType) === null || _c === void 0 ? void 0 : _c.match(/vector/i)) {
|
||||
updateKeyValueArray.push(`\`${dataKey}\`=VEC_FromText(?)`);
|
||||
}
|
||||
else {
|
||||
updateKeyValueArray.push(`\`${dataKey}\`=?`);
|
||||
}
|
||||
if (typeof parsedValue == "number") {
|
||||
updateValues.push(String(parsedValue));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user