Generic Kysely Client
hey guys,
i'm currently creating an ORM-agnostic queue engine.
Currently I'm trying to integrate kysely as new adapter.
While the adapter code is working as expected as "standalone" code, I have currently the challenge if I try to use the adapter in my example.
It's working if I only have a
Database
definition which equals my package definition.
But this isn't the case if an user wants to integrate it into their existing project.
In my adapter I have the following definition:
The DB
definition is the following:
This works inside the package and gives me all the type-safety.
In my example, I have a custom DB
definition:
This results in an typescript error that the types doesn't match ( which makes sense ๐ )
The question is now: Do you know a way to support custom DB
definitions from the outside while keeping the type-safety in the package?
It's also fine if it's not possible, maybe you could give me some hints how to solve it.
Note: Have seen something similar in the discord help ( from 2023 ), maybe this would work ( without the* Adapter code: https://github.com/noxify/vorsteh-queue/blob/adapter-kysely/packages/adapter-kysely/src/postgres-adapter.ts * Example: https://github.com/noxify/vorsteh-queue/tree/adapter-kysely/examples/kysely-postgres If you need more details/information or something else, please let me know.any
? )db.selectFrom(table) as SelectQueryBuilder<any, any, {}>
GitHub
vorsteh-queue/packages/adapter-kysely/src/postgres-adapter.ts at ad...
A powerful, ORM-agnostic queue engine for PostgreSQL 12+. Handle background jobs, scheduled tasks, and recurring processes with ease. - noxify/vorsteh-queue
GitHub
vorsteh-queue/examples/kysely-postgres at adapter-kysely ยท noxify/...
A powerful, ORM-agnostic queue engine for PostgreSQL 12+. Handle background jobs, scheduled tasks, and recurring processes with ease. - noxify/vorsteh-queue
1 Reply
Had an idea which seems to work:
Updated the constructor to:
and generate a custom client to get the correct typing inside the adapter.
Inside my adapter, i now use
this.customDbClient
instead of this.db
to get the type-safety.
After running the build command, the type errors in my example are gone.
Not sure if this is best/bad practise - any thoughts?