-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use neon for managed postgres in production
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
1 parent
7f83854
commit a6357ba
Showing
3 changed files
with
29 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |