Skip to content

Commit

Permalink
move db connection string server side (Codehagen#242)
Browse files Browse the repository at this point in the history
  • Loading branch information
shouryan01 authored May 12, 2024
1 parent d41a151 commit 9805c46
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ NEXT_PUBLIC_CLERK_AFTER_SIGN_UP_URL="/dashboard"
# -----------------------------------------------------------------------------
# Database (Neon - PostgreSQL)
# -----------------------------------------------------------------------------
NEXT_PUBLIC_DATABASE_URL=
DATABASE_URL=

# -----------------------------------------------------------------------------
# Stripe
Expand Down
3 changes: 1 addition & 2 deletions apps/www/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const env = createEnv({
// DATABASE_PASSWORD: z.string().min(1),
STRIPE_API_KEY: z.string().min(1).optional(),
STRIPE_WEBHOOK_SECRET: z.string().min(1).optional(),
DATABASE_URL: z.string().url(),
},
/**
* Specify your client-side environment variables schema here.
Expand All @@ -29,7 +30,6 @@ export const env = createEnv({
NEXT_PUBLIC_STRIPE_STD_MONTHLY_PRICE_ID: z.string().min(1).optional(),
NEXT_PUBLIC_STRIPE_PRO_PRODUCT_ID: z.string().min(1).optional(),
NEXT_PUBLIC_STRIPE_PRO_MONTHLY_PRICE_ID: z.string().min(1).optional(),
NEXT_PUBLIC_DATABASE_URL: z.string().url(),
},
/**
* Destructure all variables from `process.env` to make sure they aren't tree-shaken away.
Expand All @@ -46,7 +46,6 @@ export const env = createEnv({
process.env.NEXT_PUBLIC_STRIPE_PRO_PRODUCT_ID,
NEXT_PUBLIC_STRIPE_PRO_MONTHLY_PRICE_ID:
process.env.NEXT_PUBLIC_STRIPE_PRO_MONTHLY_PRICE_ID,
NEXT_PUBLIC_DATABASE_URL: process.env.NEXT_PUBLIC_DATABASE_URL,
},
/**
* Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation.
Expand Down
15 changes: 7 additions & 8 deletions packages/db/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { neon, Pool } from "@neondatabase/serverless";
// import { drizzle } from "drizzle-orm/neon-http";
import { drizzle } from 'drizzle-orm/neon-serverless';
import { customAlphabet } from "nanoid";

import * as asset from "./schema/asset";
import * as countryCode from "./schema/country";
import * as currency from "./schema/currency";
import * as customer from "./schema/customer";
import * as openbanking from "./schema/openbanking";
import * as provider from "./schema/provider";

import { Pool, neon } from "@neondatabase/serverless";

import { customAlphabet } from "nanoid";
// import { drizzle } from "drizzle-orm/neon-http";
import { drizzle } from 'drizzle-orm/neon-serverless';

export const schema = {
...countryCode,
...currency,
Expand All @@ -36,10 +37,8 @@ export * from "./enum";

export * from "drizzle-orm";

import { env } from "../../../apps/www/env";

const pool = new Pool({
connectionString: env.NEXT_PUBLIC_DATABASE_URL!,
connectionString: process.env.DATABASE_URL,
});

export const db = drizzle(
Expand Down

0 comments on commit 9805c46

Please sign in to comment.