Add featuredAdventures table and related code
This commit is contained in:
8
src/lib/db/db.server.ts
Normal file
8
src/lib/db/db.server.ts
Normal 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
9
src/lib/db/schema.ts
Normal 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"),
|
||||
})
|
||||
|
||||
|
||||
11
src/routes/featured/+page.server.ts
Normal file
11
src/routes/featured/+page.server.ts
Normal 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[]
|
||||
};
|
||||
})
|
||||
11
src/routes/featured/+page.svelte
Normal file
11
src/routes/featured/+page.svelte
Normal 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>
|
||||
Reference in New Issue
Block a user