diff --git a/src/app/_components/AllCountries.tsx b/src/app/_components/AllCountries.tsx
index 9d726be..437c0d6 100644
--- a/src/app/_components/AllCountries.tsx
+++ b/src/app/_components/AllCountries.tsx
@@ -1,7 +1,13 @@
+import { db } from "~/server/db";
+
export default async function AllCountries() {
+ const countries = await db.query.countries.findMany();
return (
All Countries:
+ {countries.map((country) => (
+
{country.name}
+ ))}
);
}
diff --git a/src/app/_components/WineList.tsx b/src/app/_components/WineList.tsx
index a0f41be..1abab89 100644
--- a/src/app/_components/WineList.tsx
+++ b/src/app/_components/WineList.tsx
@@ -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 (
All wines:
diff --git a/src/server/db/schema.ts b/src/server/db/schema.ts
index d6e8ad4..cba41e4 100644
--- a/src/server/db/schema.ts
+++ b/src/server/db/schema.ts
@@ -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,26 +37,29 @@ 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",
- {
- id: uuid("id").primaryKey().defaultRandom(),
- name: text("name").notNull(),
- type: typeEnum("type").notNull(),
- description: text("description"),
- imageUrl: text('imageUrl'),
- producerId: uuid("producerId").notNull(),
- subRegionId: uuid("subRegionId"),
- regionId: uuid("regionId").notNull(),
- countryId: uuid("countryId").notNull(),
- price: integer("price").notNull(),
- inStock: boolean("inStock").notNull().default(false),
- createdAt: timestamp("createdAt").defaultNow().notNull(),
- updatedAt: timestamp("updatedAt").defaultNow(),
- },
-);
+export const wines = createTable("wine", {
+ id: uuid("id").primaryKey().defaultRandom(),
+ name: text("name").notNull(),
+ type: typeEnum("type").notNull(),
+ description: text("description"),
+ imageUrl: text("imageUrl"),
+ producerId: uuid("producerId").notNull(),
+ subRegionId: uuid("subRegionId"),
+ regionId: uuid("regionId").notNull(),
+ countryId: uuid("countryId").notNull(),
+ price: integer("price").notNull(),
+ 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",
- {
- id: uuid("id").primaryKey().notNull().defaultRandom(),
- name: text("name").notNull().unique(),
- regionId: uuid("regionId").notNull(),
- },
-);
+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",
- {
- id: uuid("id").primaryKey().notNull().defaultRandom(),
- name: text("name").notNull().unique(),
- countryId: uuid("countryId").notNull(),
- },
-);
+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",
- {
- id: uuid("id").primaryKey().notNull().defaultRandom(),
- name: text("name").notNull(),
- },
-);
+export const countries = createTable("country", {
+ id: uuid("id").primaryKey().notNull().defaultRandom(),
+ name: text("name").notNull().unique(),
+});
export const countriesRelations = relations(countries, ({ many }) => ({
wines: many(wines),
- regions: many(regions)
+ regions: many(regions),
}));