import postgres from 'postgres';

const connectionString = process.env.DATABASE_URL;
if (!connectionString) throw new Error('DATABASE_URL is required');

export const sql = postgres(connectionString, {
  max: 20,
  idle_timeout: 30,
  connect_timeout: 10,
  onnotice: () => {}, // suppress notice logs
  // COUNT(*)::bigint and int8 columns as BigInt (default is string, breaks === 0n checks)
  types: {
    bigint: postgres.BigInt,
  },
});
