INNER CODE UNIT · JavaScript

update

currycan/HaTickets · desktop/src/sql/index.js:103

export const update = async (tableName, params) => {
    if (!isAllowedTable(tableName)) {
        throw new Error(`Table "${tableName}" is not allowed`);
    }

    const keys = Object.keys(params);
    if (keys.some(k => !isValidColumnName(k))) {
        throw new Error("Invalid column name detected");
    }

    const setClauses = keys.map(k => `${k} = ?`).join(", ");
    const values = keys.map(k => {
        const v = params[k];
        return typeof v === "object" ? JSON.stringify(v) : v;
    });

    return await db.execute(
        `UPDATE ${tableName} SET ${setClauses}`,

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…