Add featuredAdventures table and related code

This commit is contained in:
Sean Morley
2024-04-02 14:01:35 +00:00
parent c23ea0ce5e
commit 33122894c2
10 changed files with 1936 additions and 39 deletions

8
src/lib/db/db.server.ts Normal file
View File

@@ -0,0 +1,8 @@
import { drizzle } from 'drizzle-orm/postgres-js';
import postgres from 'postgres';
import dotenv from 'dotenv';
dotenv.config();
const { DATABASE_URL } = process.env;
const client = postgres(DATABASE_URL)
export const db = drizzle(client, {});

9
src/lib/db/schema.ts Normal file
View File

@@ -0,0 +1,9 @@
import { pgTable,serial,text } from "drizzle-orm/pg-core";
export const featuredAdventures = pgTable("featuredAdventures",{
id:serial("id").primaryKey(),
name:text("name").notNull(),
location:text("location"),
})

View File

@@ -0,0 +1,11 @@
import { db } from '$lib/db/db.server';
import { featuredAdventures } from '$lib/db/schema';
import type { Adventure } from '$lib/utils/types';
export const load = (async () => {
const result = await db.select().from(featuredAdventures)
return {
result : result as Adventure[]
};
})

View File

@@ -0,0 +1,11 @@
<script lang="ts">
export let data
console.log(data.result);
import AdventureCard from '$lib/components/AdventureCard.svelte';
</script>
<div class="grid xl:grid-cols-3 lg:grid-cols-3 md:grid-cols-2 sm:grid-cols-1 gap-4 mt-4 content-center auto-cols-auto ml-6 mr-6">
{#each data.result as adventure (adventure.id)}
<AdventureCard id={adventure.id} name={adventure.name} location={adventure.location} created={adventure.created} />
{/each}
</div>