[feat] update drizzle to v2 and add card-price relations

This commit is contained in:
2026-02-13 21:28:33 -05:00
parent 18b8774a89
commit a774360065
8 changed files with 1029 additions and 603 deletions

View File

@@ -1,12 +1,20 @@
---
import Layout from '../layouts/Main.astro';
import * as schema from '../db/schema.ts';
import { eq } from 'drizzle-orm';
//import { eq } from 'drizzle-orm';
import { db } from '../db';
//import * as schema from '../db/schema.ts';
// Get some sample Pokemon data from the database
const pokemon = await db.select().from(schema.cards).where(eq(schema.cards.productLineName, "pokemon")).limit(10);
//const pokemon = await db.select().from(schema.cards).where(eq(schema.cards.productLineName, "pokemon")).limit(16);
const pokemon = await db.query.cards.findMany({
where: { productLineName: "pokemon" },
limit: 16,
with: {
prices: true,
}
});
---
<Layout>
@@ -16,11 +24,19 @@ const pokemon = await db.select().from(schema.cards).where(eq(schema.cards.produ
<h1>Pokemon</h1>
</div>
</div>
<div class="row row-cols-1 row-cols-md-2 row-cols-lg-3 row-cols-xl-4">
<div class="row gy-4 row-cols-1 row-cols-md-2 row-cols-lg-3 row-cols-xl-4">
{pokemon.map((card) => (
<div class="col">
<img src={`/public/cards/${card.productId}.jpg`} alt={card.productName} class="img-fluid" />
{card.productName} - {card.number}
<img src={`/cards/${card.productId}.jpg`} alt={card.productName} class="img-fluid" />
<div class="row justify-content-between">
<div class="col-auto"><strong>{card.productName}</strong></div>
<div class="col-auto">{card.number}</div>
</div>
<div class="row">
{card.prices.map((price) => (
<div class="col-auto copy-small">{price.condition.split(' ').map((word) => word.charAt(0)).join('')}<br />{price.marketPrice}</div>
))}
</div>
</div>
))}