Skip to content

Commit

Permalink
Undo changes to connect.ts file
Browse files Browse the repository at this point in the history
  • Loading branch information
Draikth committed Jul 17, 2024
1 parent 8d53272 commit 9e3daeb
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions database/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import { setEnvironmentVariables } from '../util/config';

setEnvironmentVariables();

declare global {
var postgresSqlClient: Sql | undefined;
declare module globalThis {

Check warning on line 9 in database/connect.ts

View workflow job for this annotation

GitHub Actions / Jest Unit Tests, Type Checking, Linting, Playwright End to End Tests

ES2015 module syntax is preferred over namespaces
let postgresSqlClient: Sql;
}

// Connect only once to the database
// https://github.com/vercel/next.js/issues/7811#issuecomment-715259370
function connectOneTimeToDatabase() {
if (!globalThis.postgresSqlClient) {
if (!('postgresSqlClient' in globalThis)) {
globalThis.postgresSqlClient = postgres(postgresConfig);
}

Expand All @@ -34,11 +34,8 @@ function connectOneTimeToDatabase() {
...sqlParameters: Parameters<typeof globalThis.postgresSqlClient>
) => {
noStore();
if (!globalThis.postgresSqlClient) {
throw new Error('Postgres client is not initialized');
}
return globalThis.postgresSqlClient(...sqlParameters);
}) as Sql;
}) as typeof globalThis.postgresSqlClient;
}

export const sql = connectOneTimeToDatabase();
Expand Down

0 comments on commit 9e3daeb

Please sign in to comment.