More work on deployment

This commit is contained in:
Dominic Ferrando
2025-05-04 17:02:19 -04:00
parent 228b4a7b94
commit f93f9a7529
9 changed files with 31 additions and 5 deletions
BIN
View File
Binary file not shown.
+46
View File
@@ -0,0 +1,46 @@
import { Database } from "bun:sqlite";
interface ProductRecord {
webflowProductId: number;
printfulProductId: number;
}
export class ProductRecords {
private db: Database;
constructor() {
const dbPath = Bun.env.NODE_ENV === "production" ?
"/data/data.db" :
"./data/data.db";
this.db = new Database(dbPath);
}
findFromWebflow(webflowProductId: number): ProductRecord | undefined {
const row = this.db.query(`
SELECT * FROM product_records WHERE webflowProductId = ?
`).get(webflowProductId);
return row as ProductRecord | undefined;
}
findFromPrintful(printfulProductId: number): ProductRecord | undefined {
const row = this.db.query(`
SELECT * FROM product_records WHERE printfulProductId = ?
`).get(printfulProductId);
return row as ProductRecord | undefined;
}
add(record: ProductRecord): void {
this.db.run(`
INSERT OR IGNORE INTO product_records (webflowProductId, printfulProductId)
VALUES (?, ?)
`, [record.webflowProductId, record.printfulProductId]);
}
all(): ProductRecord[] {
return this.db.query(`SELECT * FROM product_records`).all() as ProductRecord[];
}
}
+5
View File
@@ -0,0 +1,5 @@
CREATE TABLE IF NOT EXISTS product_records (
webflowProductId INTEGER NOT NULL,
printfulProductId INTEGER NOT NULL,
UNIQUE(webflowProductId, printfulProductId)
)