This repository has been archived on 2024-05-29. You can view files and clone it, but cannot push or open issues or pull requests.
reset-sender-v2/scripts/export-csv.ts
2024-03-05 11:21:09 +01:00

21 lines
589 B
TypeScript

import "dotenv/config";
import { db } from "../src/db";
import * as fs from "node:fs/promises";
import { and, eq } from "drizzle-orm";
import * as schema from "../src/schema";
async function exportEmails() {
const file = await fs.open("./emails.csv", "w");
const letters = await db
.select()
.from(schema.letters)
.where(and(eq(schema.letters.confirmed, true), eq(schema.letters.subscribed, true)))
.groupBy(schema.letters.email);
for (const letter of letters) {
file.write(`${letter.email},"${letter.firstName} ${letter.lastName}"\n`);
}
}
exportEmails();