Effect CommunityEC
Effect Community2mo ago
2 replies
bartmanner

Issues with Creating a Custom Context.Tag for Typed Drizzle Database

I'm trying to create a custom Context.Tag for a typed Drizzle database, but running into type errors with @effect/sql-drizzle/Pg.

PgDrizzle.make({ schema }) returns Effect<PgRemoteDatabase<typeof schema>, never, SqlClient>, but when I use it with Layer.effect(Database, PgDrizzle.make({ schema })), I get type errors about incompatible module resolution modes for drizzle-orm imports.

PgDrizzle.layerWithConfig({ schema }) gives errors because it expects Record<string, never> instead of my actual schema type.

How can I properly create a Layer that provides my custom Database tag with the correct schema types from PgRemoteDatabase<typeof schema>?

export class Database extends Context.Tag('@org/database/Database')<
  Database,
  PgRemoteDatabase<typeof schema>
>() {}

// This doesnt work
export const DatabaseLive = Layer.effect(
  Database,
  PgDrizzle.make({ schema }),
).pipe(Layer.provide(PgLive))
Was this page helpful?