[feat] switched from mysql to postgresql
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import 'dotenv/config';
|
||||
import * as schema from '../src/db/schema.ts';
|
||||
import { db, poolConnection } from '../src/db/index.ts';
|
||||
import { db, ClosePool } from '../src/db/index.ts';
|
||||
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
@@ -43,14 +43,6 @@ function sleep(ms: number) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
function cleanProductName(name: string): string {
|
||||
// remove TCGPlayer crap
|
||||
name = name.replace(/ - .*$/, '');
|
||||
name = name.replace(/ \[.*\]/, '');
|
||||
name = name.replace(/ \(.*\)/, '');
|
||||
return name.trim();
|
||||
}
|
||||
|
||||
async function fileExists(path: string): Promise<boolean> {
|
||||
try {
|
||||
await fs.access(path);
|
||||
@@ -130,10 +122,10 @@ async function syncProductLine(productLine: string, field: string, fieldValue: s
|
||||
|
||||
for (const item of data.results[0].results) {
|
||||
|
||||
// // Check if productId already exists and skip if it does (to avoid hitting the API too much)
|
||||
// if (allProductIds.has(item.productId)) {
|
||||
// continue;
|
||||
// }
|
||||
// Check if productId already exists and skip if it does (to avoid hitting the API too much)
|
||||
if (allProductIds.has(item.productId)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
console.log(chalk.blue(` - ${item.productName} (ID: ${item.productId})`));
|
||||
|
||||
@@ -184,8 +176,9 @@ async function syncProductLine(productLine: string, field: string, fieldValue: s
|
||||
maxFulfillableQuantity: detailData.maxFulfillableQuantity,
|
||||
medianPrice: detailData.medianPrice,
|
||||
totalListings: item.totalListings,
|
||||
Artist: detailData.formattedAttributes.Artist || null,
|
||||
}).onDuplicateKeyUpdate({
|
||||
artist: detailData.formattedAttributes.Artist || null,
|
||||
}).onConflictDoUpdate({
|
||||
target: schema.tcgcards.productId,
|
||||
set: {
|
||||
productName: detailData.productName,
|
||||
//productName: cleanProductName(item.productName),
|
||||
@@ -221,7 +214,7 @@ async function syncProductLine(productLine: string, field: string, fieldValue: s
|
||||
maxFulfillableQuantity: detailData.maxFulfillableQuantity,
|
||||
medianPrice: detailData.medianPrice,
|
||||
totalListings: item.totalListings,
|
||||
Artist: detailData.formattedAttributes.Artist || null,
|
||||
artist: detailData.formattedAttributes.Artist || null,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -232,7 +225,8 @@ async function syncProductLine(productLine: string, field: string, fieldValue: s
|
||||
setCode: detailData.setCode,
|
||||
setName: detailData.setName,
|
||||
setUrlName: detailData.setUrlName,
|
||||
}).onDuplicateKeyUpdate({
|
||||
}).onConflictDoUpdate({
|
||||
target: schema.sets.setId,
|
||||
set: {
|
||||
setCode: detailData.setCode,
|
||||
setName: detailData.setName,
|
||||
@@ -249,7 +243,8 @@ async function syncProductLine(productLine: string, field: string, fieldValue: s
|
||||
condition: skuItem.condition,
|
||||
language: skuItem.language,
|
||||
variant: skuItem.variant,
|
||||
}).onDuplicateKeyUpdate({
|
||||
}).onConflictDoUpdate({
|
||||
target: schema.skus.skuId,
|
||||
set: {
|
||||
condition: skuItem.condition,
|
||||
language: skuItem.language,
|
||||
@@ -286,4 +281,4 @@ await fs.rm('missing_images.log', { force: true });
|
||||
const allProductIds = new Set(await db.select({ productId: schema.cards.productId }).from(schema.cards).then(rows => rows.map(row => row.productId)));
|
||||
|
||||
await syncTcgplayer();
|
||||
await poolConnection.end();
|
||||
await ClosePool();
|
||||
|
||||
Reference in New Issue
Block a user