better deploys
Some checks failed
Deploy to Web Server flyer-crawler.projectium.com / deploy (push) Failing after 2m24s
Some checks failed
Deploy to Web Server flyer-crawler.projectium.com / deploy (push) Failing after 2m24s
This commit is contained in:
@@ -70,16 +70,19 @@ const USER_DATA_TABLES: Record<string, string> = {
|
||||
'shopping_trips': 'user_id',
|
||||
};
|
||||
|
||||
type DBValue = string | number | boolean | null | Date | object;
|
||||
|
||||
/**
|
||||
* Generates a SQL INSERT statement for a given row of data.
|
||||
* @param table The name of the table.
|
||||
* @param row The data object for the row.
|
||||
* @returns A formatted SQL INSERT statement string.
|
||||
*/
|
||||
function generateInsertStatement(table: string, row: Record<string, any>): string {
|
||||
function generateInsertStatement(table: string, row: Record<string, DBValue>): string {
|
||||
const columns = Object.keys(row).map(col => `"${col}"`).join(', ');
|
||||
const values = Object.values(row).map(val => {
|
||||
if (val === null) return 'NULL';
|
||||
if (val instanceof Date) return `'${val.toISOString()}'`; // Handle Date objects
|
||||
if (typeof val === 'string') return `'${val.replace(/'/g, "''")}'`; // Escape single quotes
|
||||
if (typeof val === 'object') return `'${JSON.stringify(val).replace(/'/g, "''")}'`; // Handle JSONB
|
||||
return val;
|
||||
@@ -162,4 +165,3 @@ async function main() {
|
||||
}
|
||||
|
||||
main();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user