mirror of
https://github.com/nestriness/nestri.git
synced 2025-12-12 16:55:37 +02:00
⭐ feat(www): Finish up on the onboarding (#210)
Merging this prematurely to make sure the team is on the same boat... like dang! We need to find a better way to do this. Plus it has become too big
This commit is contained in:
@@ -1,30 +1,17 @@
|
||||
export * from "drizzle-orm";
|
||||
import ws from 'ws';
|
||||
import { Resource } from "sst";
|
||||
import { drizzle as neonDrizzle, NeonDatabase } from "drizzle-orm/neon-serverless";
|
||||
// import { drizzle } from 'drizzle-orm/postgres-js';
|
||||
import { Pool, neonConfig } from "@neondatabase/serverless";
|
||||
import postgres from "postgres";
|
||||
import { drizzle } from "drizzle-orm/postgres-js";
|
||||
|
||||
neonConfig.webSocketConstructor = ws;
|
||||
const client = postgres({
|
||||
idle_timeout: 30000,
|
||||
connect_timeout: 30000,
|
||||
host: Resource.Postgres.host,
|
||||
database: Resource.Postgres.database,
|
||||
user: Resource.Postgres.username,
|
||||
password: Resource.Postgres.password,
|
||||
port: Resource.Postgres.port,
|
||||
max: parseInt(process.env.POSTGRES_POOL_MAX || "1"),
|
||||
});
|
||||
|
||||
function addPoolerSuffix(original: string): string {
|
||||
const firstDotIndex = original.indexOf('.');
|
||||
if (firstDotIndex === -1) return original + '-pooler';
|
||||
return original.slice(0, firstDotIndex) + '-pooler' + original.slice(firstDotIndex);
|
||||
}
|
||||
|
||||
const dbHost = addPoolerSuffix(Resource.Database.host)
|
||||
|
||||
const client = new Pool({ connectionString: `postgres://${Resource.Database.user}:${Resource.Database.password}@${dbHost}/${Resource.Database.name}?sslmode=require` })
|
||||
|
||||
export const db = neonDrizzle(client, {
|
||||
logger:
|
||||
process.env.DRIZZLE_LOG === "true"
|
||||
? {
|
||||
logQuery(query, params) {
|
||||
console.log("query", query);
|
||||
console.log("params", params);
|
||||
},
|
||||
}
|
||||
: undefined,
|
||||
});
|
||||
export const db = drizzle(client, {});
|
||||
Reference in New Issue
Block a user