Skip to content

Commit

Permalink
db: database demo
Browse files Browse the repository at this point in the history
  • Loading branch information
leomotors committed Dec 23, 2024
1 parent 1784ead commit 3bec867
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 25 deletions.
2 changes: 1 addition & 1 deletion apps/analytics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"format": "eslint . --fix"
},
"dependencies": {
"@cugetreg/database": "workspace:*",
"@repo/database": "workspace:*",
"dotenv-cli": "^7.4.4",
"drizzle-orm": "^0.38.1",
"postgres": "^3.4.5",
Expand Down
3 changes: 2 additions & 1 deletion apps/analytics/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { user } from '@cugetreg/database'
import { count, like } from 'drizzle-orm'
import { drizzle } from 'drizzle-orm/postgres-js'
import postgres from 'postgres'

import { user } from '@repo/database'

import { emailYear, faculty } from './constants.js'

export const pgClient = postgres(process.env.DATABASE_URL as string)
Expand Down
3 changes: 3 additions & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"test:unit": "vitest"
},
"dependencies": {
"@repo/database": "workspace:*",
"@repo/ui": "workspace:*"
},
"devDependencies": {
Expand All @@ -26,8 +27,10 @@
"@typescript-eslint/eslint-plugin": "^8.18.0",
"@typescript-eslint/parser": "^8.18.0",
"autoprefixer": "^10.4.20",
"drizzle-orm": "^0.38.1",
"eslint": "^9.16.0",
"postcss": "^8.4.49",
"postgres": "^3.4.5",
"prettier": "^3.4.2",
"prettier-plugin-svelte": "^3.3.2",
"svelte": "^4.2.18",
Expand Down
7 changes: 7 additions & 0 deletions apps/web/src/lib/db.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { drizzle } from 'drizzle-orm/postgres-js'
import postgres from 'postgres'

import { env } from '$env/dynamic/private'

export const pgClient = postgres(env.DATABASE_URL as string)
export const db = drizzle(pgClient)
2 changes: 2 additions & 0 deletions apps/web/src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,5 @@
</Accordion.Content>
</Accordion.Item>
</Accordion.Root>

<a href="/dbdemo">Click to go to DB Demo</a>
17 changes: 17 additions & 0 deletions apps/web/src/routes/dbdemo/+page.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { eq } from 'drizzle-orm'

import { course } from '@repo/database'

import { db } from '$lib/db'

import type { PageServerLoad } from './$types.js'

export const load: PageServerLoad = async () => {
return {
course: await db
.select()
.from(course)
.where(eq(course.courseNo, '2110101'))
.orderBy(course.academicYear, course.semester),
}
}
11 changes: 11 additions & 0 deletions apps/web/src/routes/dbdemo/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<script lang="ts">
import type { PageData } from './$types'
export let data: PageData
</script>

<h1 class="text-h1">DB Demo</h1>

<p class="whitespace-pre">
{JSON.stringify(data.course, null, 2)}
</p>
2 changes: 1 addition & 1 deletion packages/database/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@cugetreg/database",
"name": "@repo/database",
"version": "2.0.0",
"private": true,
"type": "module",
Expand Down
56 changes: 34 additions & 22 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3bec867

Please sign in to comment.