give schema to allow drizzle queries
This commit is contained in:
8
packages/web/src/lib/db/index.ts
Normal file
8
packages/web/src/lib/db/index.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import * as schema from './schema'
|
||||||
|
import { drizzle } from 'drizzle-orm/postgres-js';
|
||||||
|
import postgres from 'postgres';
|
||||||
|
|
||||||
|
const client = postgres('postgresql://postgres:postgres@db:5432/db');
|
||||||
|
export const db = drizzle(client, { schema });
|
||||||
|
|
||||||
|
|
||||||
@@ -1,10 +1,5 @@
|
|||||||
import { relations } from 'drizzle-orm';
|
import { relations } from 'drizzle-orm';
|
||||||
import { integer, pgTable, serial, timestamp, varchar } from 'drizzle-orm/pg-core';
|
import { integer, pgTable, serial, timestamp, varchar } from 'drizzle-orm/pg-core';
|
||||||
import { drizzle } from 'drizzle-orm/postgres-js';
|
|
||||||
import postgres from 'postgres';
|
|
||||||
|
|
||||||
const client = postgres('postgresql://postgres:postgres@db:5432/db');
|
|
||||||
export const db = drizzle(client, {});
|
|
||||||
|
|
||||||
export const tasks = pgTable('tasks', {
|
export const tasks = pgTable('tasks', {
|
||||||
id: serial('id').primaryKey(),
|
id: serial('id').primaryKey(),
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
import { db, tasks } from "$lib/db/schema"
|
import { db } from "$lib/db"
|
||||||
import { eq } from "drizzle-orm"
|
|
||||||
|
|
||||||
export const load = async ({ params }) => {
|
export const load = async () => {
|
||||||
return {
|
return {
|
||||||
task: (await db.select().from(tasks).where(eq(tasks.id, params.id)))[0]
|
task: (await db.query.tasks.findFirst({
|
||||||
|
with: {
|
||||||
|
tasksToTopics: true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,4 +2,13 @@
|
|||||||
let { data } = $props();
|
let { data } = $props();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<h1 class="my-4 text-2xl font-bold text-center">{data.task.name} lol lo</h1>
|
<h1 class="my-4 text-2xl font-bold text-center">{data.task?.name}</h1>
|
||||||
|
|
||||||
|
<h2>Topics ({data.task?.tasksToTopics.length})</h2>
|
||||||
|
{#if data.task?.tasksToTopics}
|
||||||
|
{#each data.task?.tasksToTopics as topic}
|
||||||
|
<div class="rounded px-4 py-2 bg-gray-300">
|
||||||
|
{topic.topicId}
|
||||||
|
</div>
|
||||||
|
{/each}
|
||||||
|
{/if}
|
||||||
|
|||||||
Reference in New Issue
Block a user