mirror of
https://github.com/nestriness/nestri.git
synced 2025-12-12 16:55:37 +02:00
## Description This attempts to fix all database issues for all teammates ## Related Issues 1. Getting funny errors while trying to run `sst dev` 2. The neon pulumi stuff trying to create a db each time on push ## Type of Change - [x] Bug fix (non-breaking change) - [ ] New feature (non-breaking change) - [ ] Breaking change (fix or feature that changes existing functionality) - [ ] Documentation update - [ ] Other (please describe): ## Checklist - [ ] I have updated relevant documentation - [ ] My code follows the project's coding style - [x] My changes generate no new warnings/errors ## Notes for Reviewers <!-- Point out areas you'd like reviewers to focus on, questions you have, or decisions that need discussion --> ## Screenshots/Demo <!-- If applicable, add screenshots or a GIF demo of your changes (especially for UI changes) --> ## Additional Context <!-- Add any other context about the pull request here -->
30 lines
1.1 KiB
TypeScript
30 lines
1.1 KiB
TypeScript
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";
|
|
|
|
neonConfig.webSocketConstructor = ws;
|
|
|
|
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,
|
|
}); |