This commit is contained in:
Benjamin Toby 2025-05-05 15:34:42 +01:00
parent cd4a2f7902
commit 181501296a
6 changed files with 10 additions and 7 deletions

View File

@ -1351,6 +1351,7 @@ export type DsqlCrudParam<T extends {
table: string; table: string;
data?: T; data?: T;
targetId?: string | number; targetId?: string | number;
targetField?: string;
query?: DsqlCrudQueryObject<T>; query?: DsqlCrudQueryObject<T>;
sanitize?: (data?: T) => T; sanitize?: (data?: T) => T;
debug?: boolean; debug?: boolean;

View File

@ -4,6 +4,6 @@ export default function dsqlCrud<T extends {
[key: string]: any; [key: string]: any;
} = { } = {
[key: string]: any; [key: string]: any;
}>({ action, data, table, targetId, query, sanitize, debug, }: DsqlCrudParam<T>): Promise<(PostReturn & { }>({ action, data, table, targetId, query, sanitize, debug, targetField, }: DsqlCrudParam<T>): Promise<(PostReturn & {
queryObject?: ReturnType<Awaited<typeof sqlGenerator>>; queryObject?: ReturnType<Awaited<typeof sqlGenerator>>;
}) | null>; }) | null>;

View File

@ -17,7 +17,7 @@ const get_1 = __importDefault(require("../../actions/get"));
const post_1 = __importDefault(require("../../actions/post")); const post_1 = __importDefault(require("../../actions/post"));
const sql_generator_1 = __importDefault(require("../../functions/dsql/sql/sql-generator")); const sql_generator_1 = __importDefault(require("../../functions/dsql/sql/sql-generator"));
function dsqlCrud(_a) { function dsqlCrud(_a) {
return __awaiter(this, arguments, void 0, function* ({ action, data, table, targetId, query, sanitize, debug, }) { return __awaiter(this, arguments, void 0, function* ({ action, data, table, targetId, query, sanitize, debug, targetField, }) {
const finalData = sanitize ? sanitize(data) : data; const finalData = sanitize ? sanitize(data) : data;
const finalId = targetId; const finalId = targetId;
let queryObject; let queryObject;
@ -49,7 +49,7 @@ function dsqlCrud(_a) {
query: { query: {
action: "update", action: "update",
table, table,
identifierColumnName: "id", identifierColumnName: targetField || "id",
identifierValue: String(finalId), identifierValue: String(finalId),
data: finalData, data: finalData,
}, },
@ -60,7 +60,7 @@ function dsqlCrud(_a) {
query: { query: {
action: "delete", action: "delete",
table, table,
identifierColumnName: "id", identifierColumnName: targetField || "id",
identifierValue: String(finalId), identifierValue: String(finalId),
}, },
forceLocal: true, forceLocal: true,

View File

@ -1521,6 +1521,7 @@ export type DsqlCrudParam<
table: string; table: string;
data?: T; data?: T;
targetId?: string | number; targetId?: string | number;
targetField?: string;
query?: DsqlCrudQueryObject<T>; query?: DsqlCrudQueryObject<T>;
sanitize?: (data?: T) => T; sanitize?: (data?: T) => T;
debug?: boolean; debug?: boolean;

View File

@ -13,6 +13,7 @@ export default async function dsqlCrud<
query, query,
sanitize, sanitize,
debug, debug,
targetField,
}: DsqlCrudParam<T>): Promise< }: DsqlCrudParam<T>): Promise<
| (PostReturn & { | (PostReturn & {
queryObject?: ReturnType<Awaited<typeof sqlGenerator>>; queryObject?: ReturnType<Awaited<typeof sqlGenerator>>;
@ -56,7 +57,7 @@ export default async function dsqlCrud<
query: { query: {
action: "update", action: "update",
table, table,
identifierColumnName: "id", identifierColumnName: targetField || "id",
identifierValue: String(finalId), identifierValue: String(finalId),
data: finalData, data: finalData,
}, },
@ -68,7 +69,7 @@ export default async function dsqlCrud<
query: { query: {
action: "delete", action: "delete",
table, table,
identifierColumnName: "id", identifierColumnName: targetField || "id",
identifierValue: String(finalId), identifierValue: String(finalId),
}, },
forceLocal: true, forceLocal: true,

View File

@ -1,6 +1,6 @@
{ {
"name": "@moduletrace/datasquirel", "name": "@moduletrace/datasquirel",
"version": "4.5.4", "version": "4.5.5",
"description": "Cloud-based SQL data management tool", "description": "Cloud-based SQL data management tool",
"main": "dist/index.js", "main": "dist/index.js",
"bin": { "bin": {