news-analyze/server/scrape/save_scrape_data.ts
吳元皓 b62a3cda3d Add a few more database tables & made the api pull from the database
when then article exists & not ddos line today, Also made a basic
newsView with the api & the scraping script now scraps more stuff! :D
2025-05-18 11:59:58 +08:00

16 lines
500 B
TypeScript

import postgres from "~/server/components/postgres";
import { v4 as uuidv4 } from "uuid";
async function saveDataToSql(
data: { title: string; paragraph: string; author: string; origin: string },
slug: string,
) {
const sql = postgres;
await sql`
INSERT INTO articles_lt (uuid, slug, title, content, author, origin)
VALUES (${uuidv4()}, ${slug}, ${data.title}, ${data.paragraph}, ${data.author}, ${data.origin})
ON CONFLICT (slug) DO NOTHING
`;
}
export default saveDataToSql;