Effect CommunityEC
Effect Community2y ago
2 replies
joe.esteves

Issues with `@effect/sql-pg` in `bun` but not in node

Hello and good Friday for all.

I'm having some issues using @effect/sql-pg with bun (on node this is not happening)

Also I tried with @effect/sql-sqlite-bun and working as expected with that package.

I create an example to reproduce this . Is just a simple select query.
I'm running the code with bun run --watch $file

Using sqlite the result and result length are correctly printed on the console
But using sql-pg, the code halts on the Effect.provide(Layer) line. This can be confirmed with the fact that if I log before that line I see the results, but any logs after won't show up. Also if I run that on bun repl It shows the promise pending.


I add a video reproducing this. Maybe I'm missing something ?

import * as SqlClient from '@effect/sql'
import { Console, Effect as E, pipe } from 'effect'

import { Config, Secret } from 'effect'
import * as PgClient from '@effect/sql-pg'
import * as PgClientLite from '@effect/sql-sqlite-bun'


export const PgLiveLayer = PgClient.client.layer({
  database: Config.succeed('mate_back_dev'),
  host: Config.succeed('0.0.0.0'),
  port: Config.succeed(5433),
  username: Config.succeed('postgres'),
  password: Config.succeed(Secret.fromString('postgres')),
})

// Using Sqlite client works as expected
export const PgLiveLiteLayer = PgClientLite.client.layer({
  filename: Config.succeed('db.sqlite'),
})


// Using the sqlite library, works as expected. It resolves the promise and I can see the length of the array
// No matter where I provide the layer

// Using Pg client (using bun runtime) the promise keeps pending
// The code is halted on the Effect.provide(layer) 
export const getAccounts = () =>
  pipe(
    SqlClient.client.Client,
    E.flatMap((sql) => sql`SELECT * FROM accounts limit 1`),
    E.tap(Console.log),
    E.provide(PgLiveLayer),
  )

getAccounts()
  .pipe(E.runPromise)
  .then((a) => console.log(`Total accounts: ${a.length}`))


Let me know your thoughts pls ?

Thanks
Was this page helpful?