Create product and SKUs implementation

This commit is contained in:
Dominic Ferrando
2025-05-03 16:33:11 -04:00
parent bb7c041c48
commit d5da472661
7 changed files with 206 additions and 39 deletions
BIN
View File
Binary file not shown.
+42
View File
@@ -0,0 +1,42 @@
import { Database } from "bun:sqlite";
interface ProductRecord {
webflowProductId: number;
printfulProductId: number;
}
export class ProductRecords {
private db: Database;
constructor() {
this.db = new Database("./database/data.db");
}
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[];
}
}
+1 -1
View File
@@ -1,4 +1,4 @@
CREATE TABLE IF NOT EXISTS products (
CREATE TABLE IF NOT EXISTS product_records (
webflowProductId INTEGER NOT NULL,
printfulProductId INTEGER NOT NULL,
UNIQUE(webflowProductId, printfulProductId)