seguimos confiando en codex
All checks were successful
build-and-deploy / build-and-deploy (push) Successful in 1m4s
All checks were successful
build-and-deploy / build-and-deploy (push) Successful in 1m4s
This commit is contained in:
@@ -49,25 +49,25 @@
|
||||
label: 'No hay lotes registrados'
|
||||
}"
|
||||
>
|
||||
<template #codigo-cell="{ row }">
|
||||
<span class="font-mono font-semibold">{{ row.codigo || '-' }}</span>
|
||||
<template #codigo-cell="{ getValue }">
|
||||
<span class="font-mono font-semibold">{{ getValue() || '-' }}</span>
|
||||
</template>
|
||||
|
||||
<template #tipo-cell="{ row }">
|
||||
<UBadge :color="getTipoColor(row.tipo)" variant="subtle">
|
||||
{{ getTipoLabel(row.tipo) }}
|
||||
<template #tipo-cell="{ getValue }">
|
||||
<UBadge :color="getTipoColor(getValue())" variant="subtle">
|
||||
{{ getTipoLabel(getValue()) }}
|
||||
</UBadge>
|
||||
</template>
|
||||
|
||||
<template #cantidad_kg-cell="{ row }">
|
||||
<span v-if="row.cantidad_kg" class="font-medium">
|
||||
{{ row.cantidad_kg.toLocaleString('es-AR') }} kg
|
||||
<template #cantidad_kg-cell="{ getValue }">
|
||||
<span v-if="getValue()" class="font-medium">
|
||||
{{ getValue().toLocaleString('es-AR') }} kg
|
||||
</span>
|
||||
<span v-else class="text-gray-400">-</span>
|
||||
</template>
|
||||
|
||||
<template #fecha_creado-cell="{ row }">
|
||||
{{ formatDate(row.fecha_creado) }}
|
||||
<template #fecha_creado-cell="{ getValue }">
|
||||
{{ formatDate(getValue()) }}
|
||||
</template>
|
||||
|
||||
<template #actions-cell="{ row }">
|
||||
|
||||
@@ -49,17 +49,17 @@
|
||||
label: 'No hay operaciones registradas'
|
||||
}"
|
||||
>
|
||||
<template #tipo-cell="{ row }">
|
||||
<template #tipo-cell="{ row, getValue }">
|
||||
<div class="flex items-center gap-2">
|
||||
<UIcon :name="getTipoIcon(row.tipo)" class="w-4 h-4" />
|
||||
<UBadge :color="getTipoColor(row.tipo)" variant="subtle">
|
||||
{{ getTipoLabel(row.tipo) }}
|
||||
<UIcon :name="getTipoIcon(getValue())" class="w-4 h-4" />
|
||||
<UBadge :color="getTipoColor(getValue())" variant="subtle">
|
||||
{{ getTipoLabel(getValue()) }}
|
||||
</UBadge>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template #fecha-cell="{ row }">
|
||||
{{ formatDate(row.fecha) }}
|
||||
<template #fecha-cell="{ getValue }">
|
||||
{{ formatDate(getValue()) }}
|
||||
</template>
|
||||
|
||||
<template #actions-cell="{ row }">
|
||||
|
||||
@@ -4,6 +4,7 @@ import { useRuntimeConfig } from '#imports'
|
||||
const { Pool } = pg
|
||||
|
||||
let pool: pg.Pool | null = null
|
||||
let connectionStringLogged = false
|
||||
|
||||
function buildConnectionString(): string {
|
||||
const config = useRuntimeConfig()
|
||||
@@ -28,6 +29,12 @@ export function getPool(): pg.Pool {
|
||||
if (!pool) {
|
||||
const connectionString = buildConnectionString()
|
||||
|
||||
if (!connectionStringLogged && process.env.NODE_ENV !== 'production') {
|
||||
const masked = connectionString.replace(/:\/\/([^:]+):([^@]+)@/, '://$1:*****@')
|
||||
console.log('[db] Usando connectionString:', masked)
|
||||
connectionStringLogged = true
|
||||
}
|
||||
|
||||
pool = new Pool({
|
||||
connectionString,
|
||||
max: 10,
|
||||
@@ -58,19 +65,38 @@ export async function query<T = any>(
|
||||
): Promise<pg.QueryResult<T>> {
|
||||
const pool = getPool()
|
||||
const start = Date.now()
|
||||
const maxRetries = 2
|
||||
|
||||
try {
|
||||
const result = await pool.query<T>(text, params)
|
||||
const duration = Date.now() - start
|
||||
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
||||
try {
|
||||
const result = await pool.query<T>(text, params)
|
||||
const duration = Date.now() - start
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
console.log('Query ejecutada:', { text, duration: `${duration}ms`, rows: result.rowCount })
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
console.log('Query ejecutada:', { text, duration: `${duration}ms`, rows: result.rowCount })
|
||||
}
|
||||
|
||||
return result
|
||||
} catch (error: any) {
|
||||
const isAuthError = error?.code === '28P01'
|
||||
const isConnError = ['ECONNREFUSED', 'ECONNRESET', '57P01'].includes(error?.code)
|
||||
const shouldRetry = attempt < maxRetries && (isAuthError || isConnError)
|
||||
|
||||
console.error('Error ejecutando query:', { text, params, error: error?.message, code: error?.code, attempt })
|
||||
|
||||
if (shouldRetry) {
|
||||
// Pequeño backoff y reintento
|
||||
await new Promise((res) => setTimeout(res, 500 * (attempt + 1)))
|
||||
// Resetear pool en auth/conn error por si la contraseña/estado cambia en caliente
|
||||
try {
|
||||
await pool.end()
|
||||
} catch (_) {}
|
||||
pool = null
|
||||
continue
|
||||
}
|
||||
|
||||
throw error
|
||||
}
|
||||
|
||||
return result
|
||||
} catch (error) {
|
||||
console.error('Error ejecutando query:', { text, params, error })
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user