Seeking Guidance on Implementing Database Transactions with Hono and Effect

@Lucas Barake Hi Lucas, sorry to ping you directly again 😦 but I've been battling with this for quite some time now ☹️

I've watched your video Drizzle With Effect: Supporting Transactions and I'm trying to implement this in my code base.

I'm not using
@effect/platform
, I'm using
hono
.

I've checked the monorepo you provided in the video and but couldn't find how you'd then use Database.

In my codebase, I'm providing dependencies like so:
I have created endpoint.runtime.ts
export const EndpointRuntime = ManagedRuntime.make(
  Layer.mergeAll(
    PgDatabaseClient.Default,
    MySqlDatabaseClient.Default,
    ConfigLive.Default,
    ServiceOfferRepositoryLive.Default,
    LocaleRepositoryLive.Default,
    ServiceOfferServiceLive.Default,
  ),
);

Then in my route I have this:
aserviceOfferRoute.get(
  '/:id',
  getServiceOfferRoute,
  effectValidator('query', LocaleQuerySchema),
  async (ctx) => {
    const program = Effect.gen(function* (_) {
      const { locale } = ctx.req.valid('query');

      const serviceOfferService = yield* _(ServiceOfferServiceLive);
      return yield* serviceOfferService.findById(ctx.req.param('id'), locale);
    });

    const maybeServiceOffer = await EndpointRuntime.runPromiseExit(program);
    ... // rest of the code
  },
);


I don't even know if this is a good pattern 😦 but it works
Was this page helpful?