21 lines
514 B
TypeScript
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();
|