Effect CommunityEC
Effect Community2y ago
37 replies
whatplan

Connection Error When Using Custom SQL Layer with Postgres

im getting a connection error that doesnt happen if I just use
postgres
directly

import postgres from 'postgres';
const sql = postgres(process.env.POSTGRES_URL);
console.log(await sql`select * from table limit 10`)
// works fine


const GetAll = Sql.schema.findAll({
  Request: S.Void,
  Result: Models.Domain,
  execute: () => sql`select * from table limit 10`
});
const res = yield* GetAll()
console.log(res)
// errors

// layer
PgSqlClient.layer({
  url: Config.redacted('POSTGRES_URL'),
  transformQueryNames: Config.succeed(String.camelToSnake),
  transformResultNames: Config.succeed(String.snakeToCamel),
  transformJson: Config.succeed(true),
  prepare: Config.succeed(false),
}),

prepare is off bc of this guide: https://supabase.com/docs/guides/database/connecting-to-postgres#connecting-with-drizzle
timestamp=2024-07-24T19:08:38.453Z level=ERROR fiber=#144 cause="SqlError: CONNECTION_ENDED: write CONNECTION_ENDED <host>:6543
     at Query.handler (webpack-internal:///(rsc)/../../node_modules/.pnpm/postgres@3.4.4/node_modules/postgres/src/index.js:328:74)
     at Query.handle (webpack-internal:///(rsc)/../../node_modules/.pnpm/postgres@3.4.4/node_modules/postgres/src/query.js:145:65)
     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
     at Rpc.router @markprompt/Domains/GetAll"
Was this page helpful?