Skip to content

Commit

Permalink
Update connect.ts to fix eslint namespace error
Browse files Browse the repository at this point in the history
  • Loading branch information
Draikth committed Jul 17, 2024
1 parent 861fe6d commit 8d53272
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 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 module globalThis {
let postgresSqlClient: Sql;
declare global {
var postgresSqlClient: Sql | undefined;

Check warning on line 10 in database/connect.ts

View workflow job for this annotation

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

Unexpected var, use let or const instead
}

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

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

export const sql = connectOneTimeToDatabase();
Expand Down

0 comments on commit 8d53272

Please sign in to comment.