Files
cannaiq/backend/check-discounts.ts
2025-11-28 19:45:44 -07:00

34 lines
831 B
TypeScript

import pkg from 'pg';
const { Pool } = pkg;
const pool = new Pool({
connectionString: process.env.DATABASE_URL
});
async function main() {
const result = await pool.query(`
SELECT
COUNT(*) as total_products,
COUNT(CASE WHEN discount_type IS NOT NULL AND discount_value IS NOT NULL THEN 1 END) as products_with_discounts
FROM products
`);
console.log('Product Count:');
console.log(result.rows[0]);
// Get a sample of products with discounts
const sample = await pool.query(`
SELECT name, brand, regular_price, sale_price, discount_type, discount_value
FROM products
WHERE discount_type IS NOT NULL AND discount_value IS NOT NULL
LIMIT 5
`);
console.log('\nSample Products with Discounts:');
console.log(sample.rows);
await pool.end();
}
main().catch(console.error);