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}`))
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}`))