Add export script
This commit is contained in:
parent
ead2b22964
commit
a74c48bc3b
3 changed files with 25 additions and 1 deletions
2
emails.csv
Normal file
2
emails.csv
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
ondrej@nyv.lt,"Ha Ha"
|
||||||
|
onnyvlt@gmail.com,"Test Test"
|
|
|
@ -10,7 +10,8 @@
|
||||||
"preview": "astro preview",
|
"preview": "astro preview",
|
||||||
"astro": "astro",
|
"astro": "astro",
|
||||||
"test": "vitest",
|
"test": "vitest",
|
||||||
"migrate": "node --loader ts-node/esm ./scripts/migrate.ts"
|
"migrate": "node --loader ts-node/esm ./scripts/migrate.ts",
|
||||||
|
"tn": "node --loader ts-node/esm"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@astrojs/check": "^0.4.1",
|
"@astrojs/check": "^0.4.1",
|
||||||
|
|
21
scripts/export-csv.ts
Normal file
21
scripts/export-csv.ts
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
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();
|
Reference in a new issue