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