style: clean up code formatting and remove trailing whitespace
refactor: reorganize imports and fix type imports
This commit is contained in:
1 parent
d3704602fd
commit
47c04de6fe
232 files changed
+7140
-4798
No files matched your search
+19
-15
@@ -3,7 +3,7 @@
|
||||
* Gerencia pool de conexões e fornece helpers para queries
|
||||
*/
|
||||
|
||||
import { Pool, QueryResult, QueryResultRow } from "pg";
|
||||
import { Pool, type QueryResult, type QueryResultRow } from "pg";
|
||||
|
||||
let pool: Pool | null = null;
|
||||
|
||||
@@ -13,7 +13,7 @@ let pool: Pool | null = null;
|
||||
function validateEnvVars() {
|
||||
if (!process.env.PG_DB) {
|
||||
throw new Error(
|
||||
"PG_DB não está definido. Configure a variável de ambiente PG_DB com a connection string do PostgreSQL."
|
||||
"PG_DB não está definido. Configure a variável de ambiente PG_DB com a connection string do PostgreSQL.",
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -56,7 +56,7 @@ export function getPool(): Pool {
|
||||
*/
|
||||
export async function query<T extends QueryResultRow = any>(
|
||||
text: string,
|
||||
params?: any[]
|
||||
params?: any[],
|
||||
): Promise<QueryResult<T>> {
|
||||
const poolInstance = getPool();
|
||||
const start = Date.now();
|
||||
@@ -78,15 +78,15 @@ export async function query<T extends QueryResultRow = any>(
|
||||
const errorMessage = error instanceof Error ? error.message : String(error);
|
||||
const errorCode = error?.code;
|
||||
const errorStack = error instanceof Error ? error.stack : undefined;
|
||||
|
||||
|
||||
// Ignorar silenciosamente erros relacionados à tabela "items" não existir
|
||||
// Isso é esperado durante a transição e já está sendo tratado nas funções
|
||||
const isItemsTableMissing =
|
||||
errorCode === "42P01" &&
|
||||
(errorMessage.includes('relation "items" does not exist') ||
|
||||
text.includes('FROM items') ||
|
||||
text.includes('FROM "items"'));
|
||||
|
||||
const isItemsTableMissing =
|
||||
errorCode === "42P01" &&
|
||||
(errorMessage.includes('relation "items" does not exist') ||
|
||||
text.includes("FROM items") ||
|
||||
text.includes('FROM "items"'));
|
||||
|
||||
// Não logar erros esperados sobre tabela items não existir
|
||||
if (!isItemsTableMissing) {
|
||||
console.error("❌ Erro ao executar query:", {
|
||||
@@ -94,14 +94,19 @@ export async function query<T extends QueryResultRow = any>(
|
||||
error: errorMessage,
|
||||
stack: errorStack,
|
||||
});
|
||||
|
||||
|
||||
// Se o erro for sobre coluna não existir, sugerir executar migração
|
||||
if (errorMessage.includes("column") && errorMessage.includes("does not exist")) {
|
||||
console.error("\n💡 DICA: Parece que a migração do banco de dados não foi executada.");
|
||||
if (
|
||||
errorMessage.includes("column") &&
|
||||
errorMessage.includes("does not exist")
|
||||
) {
|
||||
console.error(
|
||||
"\n💡 DICA: Parece que a migração do banco de dados não foi executada.",
|
||||
);
|
||||
console.error(" Execute: pnpm run db:migrate\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -145,4 +150,3 @@ if (typeof process !== "undefined") {
|
||||
process.exit(0);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user