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