This commit is contained in:
Benjamin Toby
2025-08-02 17:14:46 +01:00
parent 9ca64cf25e
commit 71a8431de5
24 changed files with 164 additions and 48 deletions
+6 -1
View File
@@ -4,7 +4,7 @@ declare const DataTypes: readonly [{
readonly value: "0-255";
readonly argument: true;
readonly description: "Varchar is simply letters and numbers within the range 0 - 255";
readonly maxValue: 255;
readonly maxValue: 2000;
}, {
readonly title: "TINYINT";
readonly name: "TINYINT";
@@ -91,5 +91,10 @@ declare const DataTypes: readonly [{
readonly title: "TIMESTAMP";
readonly name: "TIMESTAMP";
readonly description: "Time Stamp";
}, {
readonly title: "VECTOR";
readonly name: "VECTOR";
readonly description: "Vector Field for vector-based applications";
readonly maxValue: 2147483647;
}];
export default DataTypes;
+7 -1
View File
@@ -7,7 +7,7 @@ const DataTypes = [
value: "0-255",
argument: true,
description: "Varchar is simply letters and numbers within the range 0 - 255",
maxValue: 255,
maxValue: 2000,
},
{
title: "TINYINT",
@@ -111,5 +111,11 @@ const DataTypes = [
name: "TIMESTAMP",
description: "Time Stamp",
},
{
title: "VECTOR",
name: "VECTOR",
description: "Vector Field for vector-based applications",
maxValue: 2147483647,
},
];
exports.default = DataTypes;
+7 -1
View File
@@ -6,7 +6,7 @@ const DataTypes = [
argument: true,
description:
"Varchar is simply letters and numbers within the range 0 - 255",
maxValue: 255,
maxValue: 2000,
},
{
title: "TINYINT",
@@ -110,6 +110,12 @@ const DataTypes = [
name: "TIMESTAMP",
description: "Time Stamp",
},
{
title: "VECTOR",
name: "VECTOR",
description: "Vector Field for vector-based applications",
maxValue: 2147483647,
},
] as const;
export default DataTypes;
+31 -9
View File
@@ -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
View File
@@ -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));
}
@@ -36,6 +36,9 @@ function parseDbResults({ unparsedResults, tableSchema, }) {
});
}
}
if (value && typeof value == "object") {
result[resultFieldName] = "";
}
}
parsedResults.push(result);
}
@@ -43,7 +43,11 @@ function handleIndexescreateDbFromSchema(_a) {
* @description Create new index if determined that it
* doesn't exist in MYSQL db
*/
const queryString = `CREATE${indexType == "full_text" ? " FULLTEXT" : ""} INDEX \`${alias}\` ON \`${dbFullName}\`.\`${tableName}\`(${indexTableFields === null || indexTableFields === void 0 ? void 0 : indexTableFields.map((nm) => nm.value).map((nm) => `\`${nm}\``).join(",")}) COMMENT '${(0, grab_dsql_schema_index_comment_1.default)()} ${indexName}'`;
const queryString = `CREATE${indexType == "full_text"
? " FULLTEXT"
: indexType == "vector"
? " VECTOR"
: ""} INDEX \`${alias}\` ON \`${dbFullName}\`.\`${tableName}\`(${indexTableFields === null || indexTableFields === void 0 ? void 0 : indexTableFields.map((nm) => nm.value).map((nm) => `\`${nm}\``).join(",")}) COMMENT '${(0, grab_dsql_schema_index_comment_1.default)()} ${indexName}'`;
const addIndex = yield (0, dbHandler_1.default)({ query: queryString });
}
}
+6 -1
View File
@@ -1521,6 +1521,7 @@ export type MediaUploadDataType = ImageObjectType & FileObjectType & {
privateFolder?: boolean;
overwrite?: boolean;
updatedMediaRecord?: DSQL_DATASQUIREL_USER_MEDIA;
existingMediaRecord?: DSQL_DATASQUIREL_USER_MEDIA;
existingMediaRecordId?: number;
};
export declare const ImageMimeTypes: (keyof sharp.FormatEnum)[];
@@ -1569,7 +1570,7 @@ export type DefaultEntryType = {
} & {
[k: string]: string | number | null;
};
export declare const IndexTypes: readonly ["regular", "full_text"];
export declare const IndexTypes: readonly ["regular", "full_text", "vector"];
export type LoginUserParam = {
apiKey?: string;
database: string;
@@ -1812,6 +1813,10 @@ export type AddMediaAPIBody = {
useDefault?: boolean;
update?: boolean;
};
export type ReplaceMediaAPIBody = {
mediaId: number;
media: MediaUploadDataType;
};
export declare const TargetMediaParadigms: readonly ["info", "preview"];
export type TargetMediaDataType = {
media: DSQL_DATASQUIREL_USER_MEDIA;
+1 -1
View File
@@ -186,7 +186,7 @@ exports.DefaultSQLValuesLiteral = [
dataType: "UUID",
},
];
exports.IndexTypes = ["regular", "full_text"];
exports.IndexTypes = ["regular", "full_text", "vector"];
exports.UserSelectFields = [
{
field: "first_name",
@@ -4,6 +4,7 @@ export declare const DataTypesWithTwoNumbers: (typeof DataTypes)[number]["name"]
type Return = {
type: (typeof DataTypes)[number]["name"];
limit?: number;
defaultNumber?: number;
decimal?: number;
};
export default function dataTypeParser(dataType?: string): Return;
+3 -1
View File
@@ -11,6 +11,7 @@ exports.DataTypesWithNumbers = [
"DOUBLE",
"FLOAT",
"VARCHAR",
"VECTOR",
];
exports.DataTypesWithTwoNumbers = [
"DECIMAL",
@@ -21,7 +22,7 @@ function dataTypeParser(dataType) {
if (!dataType) {
return {
type: "VARCHAR",
limit: 250,
defaultNumber: 250,
};
}
const dataTypeArray = dataType.split("(");
@@ -43,5 +44,6 @@ function dataTypeParser(dataType) {
return {
type,
limit: number ? (0, numberfy_1.default)(number) : undefined,
defaultNumber: type == "VECTOR" ? 120 : 10,
};
}
+1 -1
View File
@@ -1,4 +1,4 @@
declare const APIParadigms: readonly ["crud", "media", "schema"];
import { APIParadigms } from "../types";
type Params = {
version?: string;
paradigm?: (typeof APIParadigms)[number];
-1
View File
@@ -1,7 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = grabAPIBasePath;
const APIParadigms = ["crud", "media", "schema"];
function grabAPIBasePath({ version, paradigm }) {
let basePath = `/api/v${version || "1"}`;
if (paradigm) {