added card to show all wines in db
All checks were successful
Vercel Production Deployment / Deploy-Production (push) Successful in 1m24s

This commit is contained in:
ChrQR 2024-05-28 15:39:21 +02:00
parent 2f158c49d6
commit e70ff89833
3 changed files with 52 additions and 52 deletions

View File

@ -1,7 +1,13 @@
import { db } from "~/server/db";
export default async function AllCountries() {
const countries = await db.query.countries.findMany();
return (
<div className="pt-4">
<h1 className="text-2xl">All Countries:</h1>
{countries.map((country) => (
<p key={country.id}>{country.name}</p>
))}
</div>
);
}

View File

@ -2,8 +2,8 @@
import { db } from "~/server/db";
import WineName from "./WineName";
const wines = await db.query.wines.findMany();
export default async function WineList() {
const wines = await db.query.wines.findMany();
return (
<div className="pt-4">
<h1 className="text-2xl">All wines:</h1>

View File

@ -6,7 +6,7 @@ import {
pgTableCreator,
text,
timestamp,
uuid
uuid,
} from "drizzle-orm/pg-core";
import { relations } from "drizzle-orm";
@ -17,9 +17,9 @@ export const producers = createTable(
"producer",
{
id: uuid("id").primaryKey().defaultRandom(),
name: text("name").notNull(),
name: text("name").notNull().unique(),
description: text("description"),
imageUrl: text('imageUrl'),
imageUrl: text("imageUrl"),
countryId: uuid("countryId").notNull(),
createdAt: timestamp("createdAt").defaultNow().notNull(),
updatedAt: timestamp("updatedAt").defaultNow(),
@ -37,16 +37,20 @@ export const producersRelations = relations(producers, ({ many }) => ({
}));
// Wines schema
export const typeEnum = pgEnum('type', ['sparkling', 'white', 'red', 'sweet', 'other']);
export const typeEnum = pgEnum("type", [
"sparkling",
"white",
"red",
"sweet",
"other",
]);
export const wines = createTable(
"wine",
{
export const wines = createTable("wine", {
id: uuid("id").primaryKey().defaultRandom(),
name: text("name").notNull(),
type: typeEnum("type").notNull(),
description: text("description"),
imageUrl: text('imageUrl'),
imageUrl: text("imageUrl"),
producerId: uuid("producerId").notNull(),
subRegionId: uuid("subRegionId"),
regionId: uuid("regionId").notNull(),
@ -55,8 +59,7 @@ export const wines = createTable(
inStock: boolean("inStock").notNull().default(false),
createdAt: timestamp("createdAt").defaultNow().notNull(),
updatedAt: timestamp("updatedAt").defaultNow(),
},
);
});
// many-to-one relationship wine -> producer
export const winesRelations = relations(wines, ({ one }) => ({
@ -75,53 +78,44 @@ export const winesRelations = relations(wines, ({ one }) => ({
country: one(countries, {
fields: [wines.countryId],
references: [countries.id],
})
}),
}));
export const subRegions = createTable(
"subRegion",
{
export const subRegions = createTable("subRegion", {
id: uuid("id").primaryKey().notNull().defaultRandom(),
name: text("name").notNull().unique(),
regionId: uuid("regionId").notNull(),
},
);
});
export const subRegionsRelations = relations(subRegions, ({ many, one }) => ({
wines: many(wines),
region: one(regions, {
fields: [subRegions.regionId],
references: [regions.id]
})
references: [regions.id],
}),
}));
export const regions = createTable(
"region",
{
export const regions = createTable("region", {
id: uuid("id").primaryKey().notNull().defaultRandom(),
name: text("name").notNull().unique(),
countryId: uuid("countryId").notNull(),
},
);
});
export const regionsRelations = relations(regions, ({ many, one }) => ({
wines: many(wines),
subRegions: many(subRegions),
country: one(countries, {
fields: [regions.countryId],
references: [countries.id]
})
references: [countries.id],
}),
}));
export const countries = createTable(
"country",
{
export const countries = createTable("country", {
id: uuid("id").primaryKey().notNull().defaultRandom(),
name: text("name").notNull(),
},
);
name: text("name").notNull().unique(),
});
export const countriesRelations = relations(countries, ({ many }) => ({
wines: many(wines),
regions: many(regions)
regions: many(regions),
}));