Using drizzle with a DI container - which type to use? Getting error
I'm using the mysql driver and I am attempting to use my DI container (Inversify) to inject the drizzle db into my repository classes, but having trouble with which type to use. I'm actually getting a runtime error.
I've created a db like this:
export const db = drizzle(poolConnection);
and my Inversify config is pretty simple: container.bind<MySql2Database>(TYPES.Database).toConstantValue(db);
, and then my repository class constructor simply has a field @inject(TYPES.Database) private db: MySql2Database,
. I'm pretty sure this is all a standard setup
I'm not getting any Typescript errors, but the dev server fails to run with this message:
And when I peek into the library code indeed MySql2Database
is not exported, sort of... the driver.ts file has MySql2Database
defined, but the driver.js file doesn't have it exported - instead it is exported like this: MySql2Database as MySqlDatabase
.
So I'm not sure what to do here. I think it might be a bug in the drizzle-orm/mysql2 package, but also I'm not sure if I am even approaching this correctly in the first place. Any tips would be welcome.0 Replies