This commit is contained in:
2026-01-03 05:34:24 +01:00
parent f0d44092e5
commit 290dfe303c
49 changed files with 1497 additions and 1016 deletions
+3 -3
View File
@@ -33,6 +33,7 @@ export default async function dsqlCrud<
deleteKeyValuesOperator,
dbConfig,
query,
onDuplicate,
} = params;
const finalData = (sanitize ? sanitize({ data }) : data) as T;
@@ -65,9 +66,6 @@ export default async function dsqlCrud<
case "get":
return await dsqlCrudGet<T, K>(params);
// case "batch-get":
// return await dsqlCrudBatchGet(params);
case "insert":
const INSERT_RESULT = await addDbEntry({
data: finalData,
@@ -77,7 +75,9 @@ export default async function dsqlCrud<
debug,
tableSchema,
dbConfig,
onDuplicate,
});
return INSERT_RESULT;
case "update":
@@ -84,10 +84,17 @@ export default function ({
targetChildTableParentDatabase.tables[
targetChildTableParentDatabaseTableIndex
].fields = [...currentTableSchema.fields];
targetChildTableParentDatabase.tables[
targetChildTableParentDatabaseTableIndex
].indexes = [...(currentTableSchema.indexes || [])];
targetChildTableParentDatabase.tables[
targetChildTableParentDatabaseTableIndex
].uniqueConstraints = [
...(currentTableSchema.uniqueConstraints || []),
];
writeUpdatedDbSchema({
dbSchema: targetChildTableParentDatabase,
userId,
@@ -221,6 +228,9 @@ export default function ({
targetParentDatabaseTable.fields;
newCurrentDbSchema.tables[currentTableSchemaIndex].indexes =
targetParentDatabaseTable.indexes;
newCurrentDbSchema.tables[
currentTableSchemaIndex
].uniqueConstraints = targetParentDatabaseTable.uniqueConstraints;
writeUpdatedDbSchema({ dbSchema: targetParentDatabase, userId });
}
+8 -2
View File
@@ -1,5 +1,5 @@
type Param = {
type: "foreign_key" | "index" | "user";
type: "foreign_key" | "index" | "user" | "unique_constraint";
userId?: string | number;
addDate?: boolean;
};
@@ -10,15 +10,21 @@ type Param = {
*/
export default function grabSQLKeyName({ type, userId, addDate }: Param) {
let prefixParadigm = (() => {
if (type == "unique_constraint") return "unq";
if (type == "foreign_key") return "fk";
if (type == "index") return "indx";
if (type == "user") return "user";
return null;
})();
const uuid = crypto.randomUUID();
const uidPrefx = uuid.split("-")[0];
let key = `dsql`;
if (prefixParadigm) key += `_${prefixParadigm}`;
if (userId) key += `_${userId}`;
if (addDate) key += `_${Date.now()}`;
if (addDate) key += `_${uidPrefx}`;
return key;
}