Clarification on Layer Composition and Dependencies in Effect Typescript

It seems I might need clarifications on Layers and their composition as I am running into a scenario I don't fully understand.
// database.ts
const PgLive = PgClient.layer({ url: Redacted.make(env.DATABASE_URL) })
export class Drizzle extends Effect.Service<Drizzle>()('Drizzle', {
    effect: PgDrizzle.make({ casing: 'snake_case' }),
}) {
    static Client = this.Default.pipe(Layer.provide(PgLive))
}
export const DatabaseLive = Layer.mergeAll(PgLive, Drizzle.Client)
// query-repository.ts
export class BuildingQueryRepository extends Effect.Service<BuildingQueryRepository>()(
    'building/QueryRepository',
    {
        dependencies: [Drizzle.Default],
        effect: Effect.gen(function* () {
            const db = yield* Drizzle
            // ...
            return { ... }
        }),
    },
) {}
// query-service.ts
export class BuildingQueryService extends Effect.Service<BuildingQueryService>()('building/QueryService', {
    dependencies: [BuildingQueryRepository.Default],
    effect: Effect.gen(function* () {
        const buildingQueryRepository = yield* BuildingQueryRepository
        // ...
        return { .... }
    }),
}) {}

With those services I have a program such as this:
const fetchData = Effect.fn('fetchData')(function* (id: string) {
    const service = yield* BuildingQueryService
    return yield* service.getByPlanetId(PlanetId.make(id))
})

My runtime setup is this:
const MainLayer = Layer.mergeAll(DatabaseLive)
export const ServerRuntime = ManagedRuntime.make(MainLayer)

Since fetchData has a dependency on BuildingQueryService I was of the impression that adding BuildingQueryService.Default to the MainLayer suffices but that makes the resulting layer dependent on SqlClient. I was of the impression that my DatabaseLive layer would already provide the necessary implementation for that. What's the right way to structure this?
Was this page helpful?