mirror of
https://github.com/felipegcoutinho/openmonetis.git
synced 2026-03-10 04:51:47 +00:00
refactor: migrate from ESLint to Biome and extract SQL queries to data.ts
- Replace ESLint with Biome for linting and formatting - Configure Biome with tabs, double quotes, and organized imports - Move all SQL/Drizzle queries from page.tsx files to data.ts files - Create new data.ts files for: ajustes, dashboard, relatorios/categorias - Update existing data.ts files: extrato, fatura (add lancamentos queries) - Remove all drizzle-orm imports from page.tsx files - Update README.md with new tooling info Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
36
lib/db.ts
36
lib/db.ts
@@ -1,39 +1,39 @@
|
||||
import * as schema from "@/db/schema";
|
||||
import { drizzle, type PgDatabase } from "drizzle-orm/node-postgres";
|
||||
import { Pool } from "pg";
|
||||
import * as schema from "@/db/schema";
|
||||
|
||||
const globalForDb = globalThis as unknown as {
|
||||
db?: PgDatabase<typeof schema>;
|
||||
pool?: Pool;
|
||||
db?: PgDatabase<typeof schema>;
|
||||
pool?: Pool;
|
||||
};
|
||||
|
||||
let _db: PgDatabase<typeof schema> | undefined;
|
||||
let _pool: Pool | undefined;
|
||||
|
||||
function getDb() {
|
||||
if (_db) return _db;
|
||||
if (_db) return _db;
|
||||
|
||||
const { DATABASE_URL } = process.env;
|
||||
const { DATABASE_URL } = process.env;
|
||||
|
||||
if (!DATABASE_URL) {
|
||||
throw new Error("DATABASE_URL env variable is not set");
|
||||
}
|
||||
if (!DATABASE_URL) {
|
||||
throw new Error("DATABASE_URL env variable is not set");
|
||||
}
|
||||
|
||||
_pool = globalForDb.pool ?? new Pool({ connectionString: DATABASE_URL });
|
||||
_db = globalForDb.db ?? drizzle(_pool, { schema });
|
||||
_pool = globalForDb.pool ?? new Pool({ connectionString: DATABASE_URL });
|
||||
_db = globalForDb.db ?? drizzle(_pool, { schema });
|
||||
|
||||
if (process.env.NODE_ENV !== "production") {
|
||||
globalForDb.pool = _pool;
|
||||
globalForDb.db = _db;
|
||||
}
|
||||
if (process.env.NODE_ENV !== "production") {
|
||||
globalForDb.pool = _pool;
|
||||
globalForDb.db = _db;
|
||||
}
|
||||
|
||||
return _db;
|
||||
return _db;
|
||||
}
|
||||
|
||||
export const db = new Proxy({} as PgDatabase<typeof schema>, {
|
||||
get(_, prop) {
|
||||
return Reflect.get(getDb(), prop);
|
||||
},
|
||||
get(_, prop) {
|
||||
return Reflect.get(getDb(), prop);
|
||||
},
|
||||
});
|
||||
|
||||
export { schema };
|
||||
|
||||
Reference in New Issue
Block a user