Db requirement

Hi everyone. Effect beginner here.
I'm trying to understand how to manage Requirements (the R part of Effect<A,E,R>).

Here is what I'm trying to do (but don't know the synthax of):

Have a queryDb<T>(query: string, params: any[]) function that returns a Effect<T, MySQLError, { db: PoolConnection }>.

To provide a more concrete situation, here is what it could look like:

export const queryDb = <T = any>(
  query: string,
  params: QueryParam[] = [],
): Effect<T, MySQLError, { db: PoolConnection }> =>
  EffectO.fromCallback(
    ({ db }, callback) => {
      db.query(query, params, callback);
    },
    (error) => new MySQLError(error as MysqlError),
  );


Then outside, once it's time to run the program, we would do something like runPromise(provideService(myProgramm, { db }))

I know the synthax isn't right, it's just to illustrate what i'm trying to do.

I saw that we are supposed to use "Context.Tag" somehow, but the examples on the website aren't sufficient for me to understand.
Can someone please help me?
Was this page helpful?