fix: use drizzle
This commit is contained in:
@@ -1,6 +0,0 @@
|
||||
import { drizzle } from 'drizzle-orm/postgres-js';
|
||||
import postgres from 'postgres';
|
||||
import { DATABASE_URL } from '$env/static/private';
|
||||
|
||||
const client = postgres(DATABASE_URL);
|
||||
export const db = drizzle(client, {});
|
||||
@@ -1,4 +1,9 @@
|
||||
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 topics = pgTable('topics', {
|
||||
id: serial('id').primaryKey(),
|
||||
@@ -16,14 +21,6 @@ export const universities = pgTable('universities', {
|
||||
updatedAt: timestamp('updated_at').defaultNow()
|
||||
});
|
||||
|
||||
export const courses = pgTable('courses', {
|
||||
id: serial('id').primaryKey(),
|
||||
name: varchar('name', { length: 256 }),
|
||||
universityId: integer('university_id').references(() => universities.id),
|
||||
createdAt: timestamp('created_at').defaultNow(),
|
||||
updatedAt: timestamp('updated_at').defaultNow()
|
||||
});
|
||||
|
||||
export const certificates = pgTable('certificates', {
|
||||
id: serial('id').primaryKey(),
|
||||
name: varchar('name', { length: 256 }),
|
||||
@@ -32,17 +29,18 @@ export const certificates = pgTable('certificates', {
|
||||
updatedAt: timestamp('updated_at').defaultNow()
|
||||
});
|
||||
|
||||
export const books = pgTable('books', {
|
||||
id: serial('id').primaryKey(),
|
||||
name: varchar('name', { length: 256 }),
|
||||
progress: integer('progress').default(0),
|
||||
createdAt: timestamp('created_at').defaultNow(),
|
||||
updatedAt: timestamp('updated_at').defaultNow()
|
||||
});
|
||||
|
||||
export const publications = pgTable('publications', {
|
||||
id: serial('id').primaryKey(),
|
||||
name: varchar('name', { length: 256 }),
|
||||
createdAt: timestamp('created_at').defaultNow(),
|
||||
updatedAt: timestamp('updated_at').defaultNow()
|
||||
});
|
||||
|
||||
export const tasks = pgTable('topics', {
|
||||
id: serial('id').primaryKey(),
|
||||
name: varchar('name', { length: 256 }),
|
||||
createdAt: timestamp('created_at').defaultNow(),
|
||||
updatedAt: timestamp('updated_at').defaultNow()
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// import { db } from '$lib/db/db.server';
|
||||
// import { myTable } from '$lib/db/schema';
|
||||
// import { myTable, db } from '$lib/db/schema';
|
||||
import type { PageServerLoad } from './$types';
|
||||
|
||||
export const load = (async () => {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { db, tasks } from "$lib/db/schema"
|
||||
|
||||
export const load = async () => {
|
||||
return {
|
||||
tasks: []
|
||||
tasks: await db.select().from(tasks)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,13 @@
|
||||
let { data } = $props();
|
||||
</script>
|
||||
|
||||
<h1 class="font-bold text-xl text-center m-4">Tasks ({data.tasks.length})</h1>
|
||||
<div class="flex justify-center items-center">
|
||||
<h1 class="font-bold text-xl text-center m-4">Tasks ({data.tasks.length})</h1>
|
||||
<a href={'/progress/create'}>
|
||||
<button class="px-4 py-2 rounded bg-green-500">Create</button>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
@@ -15,9 +21,9 @@
|
||||
<tbody>
|
||||
{#each data.tasks as task}
|
||||
<tr>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td>{task.id}</td>
|
||||
<td>{task.name}</td>
|
||||
<td>{task.progress}</td>
|
||||
<td><button>Delete</button></td>
|
||||
</tr>
|
||||
{/each}</tbody
|
||||
|
||||
12
packages/web/src/routes/progress/create/+page.server.ts
Normal file
12
packages/web/src/routes/progress/create/+page.server.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { db, tasks } from "$lib/db/schema"
|
||||
import { redirect } from "@sveltejs/kit"
|
||||
|
||||
export const actions = {
|
||||
default: async ({ request }) => {
|
||||
const data = await request.formData()
|
||||
|
||||
await db.insert(tasks).values({ name: data.get('name') })
|
||||
|
||||
redirect(303, '/progress')
|
||||
}
|
||||
}
|
||||
10
packages/web/src/routes/progress/create/+page.svelte
Normal file
10
packages/web/src/routes/progress/create/+page.svelte
Normal file
@@ -0,0 +1,10 @@
|
||||
<form method="post" class="flex flex-col items-center gap-4">
|
||||
<h1 class="font-bold text-xl mt-8 mb-4">Create Task</h1>
|
||||
|
||||
<div class="flex gap-4">
|
||||
<label for="name">Name: </label>
|
||||
<input type="text" id="name" class="border rounded" />
|
||||
</div>
|
||||
|
||||
<button class="px-4 py-2 rounded bg-green-500 m-4">Submit</button>
|
||||
</form>
|
||||
Reference in New Issue
Block a user