Seeking Advice on Layers Replacement in Database Transactions

I have a small issue related to Layers replacement. Working Database Transactions wrappers. I'm not sure if I'm using the recommended approach.
Please see code snippet
  // NB: 📝 I have a global ModelDatabase Layer

  const result = yield* Effect.tryPromise(() => {
      return db.transaction((tx) => {
        // Creating a temporary ModelDatabase Layer
        const TxModelDatabase = Layer.succeed(ModelDatabase, tx);

        // Replacing the global ModelDatabase Layer with the Temp (TxModelDatabase Layer)
        const requirements_ = Layer.merge(requirements, TxModelDatabase);

        const program = Effect.provide(effect, requirements_);
        
        // because I'm using runPromise the Errors resolve to An UnknownError 
        // leaving me with the option of manually resolving them. 
        return Effect.runPromise(program);
      });
    });
Was this page helpful?