fix SQL export for MySQL specific date format;
fix PublisherForm
This commit is contained in:
@ -16,7 +16,7 @@ import ShiftsList from "../publisher/ShiftsList.tsx";
|
||||
import ConfirmationModal from "../ConfirmationModal";
|
||||
import { UserRole } from "@prisma/client";
|
||||
|
||||
const { data: session } = useSession()
|
||||
// const { data: session } = useSession()
|
||||
|
||||
// import { Tabs, List } from 'tw-elements'
|
||||
|
||||
|
@ -18,28 +18,33 @@ const parseQueryParams = (query: any) => {
|
||||
};
|
||||
|
||||
|
||||
// Helper function to escape and quote strings, handle nulls and other types
|
||||
const serializeValue = (value) => {
|
||||
if (value === null || value === undefined) {
|
||||
return 'NULL';
|
||||
}
|
||||
if (typeof value === 'string') {
|
||||
return `'${value.replace(/'/g, "''")}'`; // escape single quotes in SQL string
|
||||
// Escape single quotes and backslashes for MySQL
|
||||
return `'${value.replace(/\\/g, "\\\\").replace(/'/g, "''")}'`;
|
||||
}
|
||||
if (typeof value === 'boolean') {
|
||||
return value ? 'true' : 'false';
|
||||
// MySQL uses 1 and 0 for TRUE and FALSE
|
||||
return value ? '1' : '0';
|
||||
}
|
||||
if (typeof value === 'number') {
|
||||
return value;
|
||||
}
|
||||
if (value instanceof Date) {
|
||||
// Format date objects to MySQL date strings
|
||||
return `'${value.toISOString().slice(0, 19).replace('T', ' ')}'`;
|
||||
}
|
||||
if (Array.isArray(value) || typeof value === 'object') {
|
||||
// Convert arrays and objects to JSON strings and escape them
|
||||
return `'${JSON.stringify(value).replace(/'/g, "''")}'`;
|
||||
return `'${JSON.stringify(value).replace(/\\/g, "\\\\").replace(/'/g, "''")}'`;
|
||||
}
|
||||
return value;
|
||||
};
|
||||
|
||||
// Function to generate SQL INSERT statements from data
|
||||
// Function to generate SQL INSERT statements for MySQL from data
|
||||
const generateSQL = (data, tableName) => {
|
||||
return data.map(item => {
|
||||
const columns = Object.keys(item).join(", ");
|
||||
@ -47,7 +52,6 @@ const generateSQL = (data, tableName) => {
|
||||
return `INSERT INTO ${tableName} (${columns}) VALUES (${values});`;
|
||||
}).join("\n");
|
||||
};
|
||||
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
const prisma: PrismaClient = common.getPrismaClient();
|
||||
const modelArray = (req.query.model || (req.body && req.body.model)) as string[];
|
||||
|
Reference in New Issue
Block a user