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-01 15:10:02 +01:00

21 lines
514 B
TypeScript

import "dotenv/config";
import { db } from "../src/db";
import * as fs from "node:fs/promises";
async function exportEmails() {
const file = await fs.open("./emails.csv", "w");
const letters = await db
.selectFrom("letters")
.where("confirmed", "=", 1)
.groupBy("email")
.select(["email", "firstName", "lastName"])
.execute();
for (const letter of letters) {
console.log(letter);
file.write(`${letter.email},"${letter.firstName} ${letter.lastName}"\n`);
}
}
exportEmails();