Skip to content

Commit

Permalink
feat(svelte-ui): add drizzle ORM for db access
Browse files Browse the repository at this point in the history
I'll be trying Drizzle cause it looks interesting and it's one of the
recommended tools when initializing a new SvelteKit project.

For now, I'll just use my existing Prisma schema and use a
database-first approach with `drizzle pull`.

Ref: https://orm.drizzle.team/docs/overview
Ref: https://orm.drizzle.team/docs/migrations
  • Loading branch information
nicholaschiang committed Nov 25, 2024
1 parent e50c08f commit de25465
Show file tree
Hide file tree
Showing 7 changed files with 682 additions and 2 deletions.
1 change: 1 addition & 0 deletions svelte-ui/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DATABASE_URL="postgres://root:mysecretpassword@localhost:5432/local"
10 changes: 10 additions & 0 deletions svelte-ui/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
services:
db:
image: postgres
restart: always
ports:
- 5432:5432
environment:
POSTGRES_USER: root
POSTGRES_PASSWORD: mysecretpassword
POSTGRES_DB: local
14 changes: 14 additions & 0 deletions svelte-ui/drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { defineConfig } from 'drizzle-kit';
if (!process.env.DATABASE_URL) throw new Error('DATABASE_URL is not set');

export default defineConfig({
schema: './src/lib/server/db/schema.ts',

dbCredentials: {
url: process.env.DATABASE_URL
},

verbose: true,
strict: true,
dialect: 'postgresql'
});
11 changes: 9 additions & 2 deletions svelte-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,19 @@
"lint": "prettier --check . && eslint .",
"test:unit": "vitest",
"test": "npm run test:unit -- --run && npm run test:e2e",
"test:e2e": "playwright test"
"test:e2e": "playwright test",
"db:start": "docker compose up",
"db:push": "drizzle-kit push",
"db:migrate": "drizzle-kit migrate",
"db:studio": "drizzle-kit studio"
},
"devDependencies": {
"@playwright/test": "^1.45.3",
"@sveltejs/adapter-auto": "^3.0.0",
"@sveltejs/kit": "^2.0.0",
"@sveltejs/vite-plugin-svelte": "^4.0.0",
"autoprefixer": "^10.4.20",
"drizzle-kit": "^0.22.0",
"eslint": "^9.7.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-svelte": "^2.36.0",
Expand All @@ -36,6 +41,8 @@
"vitest": "^2.0.4"
},
"dependencies": {
"@tailwindcss/forms": "^0.5.9"
"@tailwindcss/forms": "^0.5.9",
"drizzle-orm": "^0.33.0",
"postgres": "^3.4.4"
}
}
Loading

0 comments on commit de25465

Please sign in to comment.