Skip to content

Commit

Permalink
feat: use neon for managed postgres in production
Browse files Browse the repository at this point in the history
I will use Neon for simplicity until I switch to a local client-side
IndexedDB or SQLite solution. Neon is what Vercel Postgres is. I figured
I would use Neon directly.

Ref: https://vercel.com/docs/storage/vercel-postgres#neon-partnership
Ref: https://orm.drizzle.team/docs/get-started/neon-new
  • Loading branch information
nicholaschiang committed Nov 25, 2024
1 parent 7f83854 commit a6357ba
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
1 change: 1 addition & 0 deletions svelte-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"vitest": "^2.0.4"
},
"dependencies": {
"@neondatabase/serverless": "^0.10.3",
"@supabase/sql-formatter": "^4.0.3",
"@tailwindcss/forms": "^0.5.9",
"@tailwindcss/typography": "^0.5.15",
Expand Down
22 changes: 20 additions & 2 deletions svelte-ui/pnpm-lock.yaml

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

16 changes: 8 additions & 8 deletions svelte-ui/src/lib/server/db/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { drizzle } from "drizzle-orm/node-postgres"
import { drizzle as postgres } from "drizzle-orm/node-postgres"
import { drizzle as neon } from "drizzle-orm/neon-http"
import { env } from "$env/dynamic/private"

import * as tables from "./schema/tables"
import * as relations from "./schema/relations"

const schema = { ...tables, ...relations }

if (!env.DATABASE_URL) throw new Error("DATABASE_URL is not set")

export const db = drizzle({
schema,
logger: true,
connection: env.DATABASE_URL,
})
const schema = { ...tables, ...relations }
const config = { schema, logger: true, connection: env.DATABASE_URL }

export const db = env.DATABASE_URL.includes("neon")
? neon(config)
: postgres(config)

0 comments on commit a6357ba

Please sign in to comment.