Compare commits
3 Commits
f0125fd472
...
14b14f9f26
Author | SHA1 | Date | |
---|---|---|---|
14b14f9f26 | |||
2c5fcbcbdb | |||
7590e54392 |
@ -2,6 +2,7 @@ import { db } from "~/server/db";
|
||||
|
||||
export default async function AllRegions() {
|
||||
const allRegions = await db.query.regions.findMany();
|
||||
const allCountries = await db.query.countries.findMany();
|
||||
return (
|
||||
<div className="pt-4">
|
||||
<h1 className="text-2xl">All Regions:</h1>
|
||||
@ -9,7 +10,14 @@ export default async function AllRegions() {
|
||||
<>
|
||||
<ul>
|
||||
{allRegions.map((region) => (
|
||||
<li key={region.id}>{region.name}</li>
|
||||
<li key={region.id}>
|
||||
{region.name} -{" "}
|
||||
{
|
||||
allCountries.find(
|
||||
(country) => country.id === region.countryId,
|
||||
)?.name
|
||||
}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</>
|
||||
|
@ -11,7 +11,6 @@ import {
|
||||
SelectValue,
|
||||
} from "~/components/ui/select";
|
||||
import { useFormState } from "react-dom";
|
||||
import { init } from "next/dist/compiled/webpack/webpack";
|
||||
|
||||
interface Country {
|
||||
id: string;
|
||||
|
@ -25,7 +25,7 @@ export const addRegion = async (prevstate: any, formData: FormData) => {
|
||||
const confirmedRegion = await db
|
||||
.insert(regions)
|
||||
.values(newRegion.data)
|
||||
.onConflictDoNothing({ target: regions.name })
|
||||
.onConflictDoNothing()
|
||||
.returning({ name: regions.name });
|
||||
if (!confirmedRegion[0]?.name) {
|
||||
return {
|
||||
|
@ -7,6 +7,7 @@ import {
|
||||
text,
|
||||
timestamp,
|
||||
uuid,
|
||||
unique,
|
||||
} from "drizzle-orm/pg-core";
|
||||
import { relations } from "drizzle-orm";
|
||||
|
||||
@ -95,11 +96,17 @@ export const subRegionsRelations = relations(subRegions, ({ many, one }) => ({
|
||||
}),
|
||||
}));
|
||||
|
||||
export const regions = createTable("region", {
|
||||
export const regions = createTable(
|
||||
"region",
|
||||
{
|
||||
id: uuid("id").primaryKey().notNull().defaultRandom(),
|
||||
name: text("name").notNull().unique(),
|
||||
name: text("name").notNull(),
|
||||
countryId: uuid("countryId").notNull(),
|
||||
});
|
||||
},
|
||||
(t) => ({
|
||||
uniqueRegion: unique().on(t.name, t.countryId),
|
||||
}),
|
||||
);
|
||||
|
||||
export const regionsRelations = relations(regions, ({ many, one }) => ({
|
||||
wines: many(wines),
|
||||
|
Loading…
Reference in New Issue
Block a user