kysely-org / kysely

A type-safe typescript SQL query builder
https://kysely.dev
MIT License
10.8k stars 275 forks source link

Any way to migrate from knex? #312

Closed ffxsam closed 1 year ago

ffxsam commented 1 year ago

I have an existing project (using knex) with tons of migrations and seeds. Is there some way to migrate to kysely seamlessly? Either by reading the current DB schema and creating an initial migration, or translating all the migrations and moving data from knex_migrations and knex_migrations_lock into new tables.

igalklebanov commented 1 year ago

Hey 👋

There's nothing like that in the core or ecosystem (afaik).

Feels to me that this shouldn't be part of the core. It would require a lot of work, and I'm not sure it aligns with the project's goals.

Hope this gap doesn't discourage you from using kysely.

ffxsam commented 1 year ago

I definitely agree, it shouldn't be part of the core. I was just wondering if there's some set of steps I can take to carefully move from knex to kysely.

Random side question: is it possible with kysely to simply build a SQL query string but not actually execute it? We use RDS Data API, so it wouldn't make sense to use kysely to execute SQL statements.

igalklebanov commented 1 year ago

I was just wondering if there's some set of steps I can take to carefully move from knex to kysely.

Well, I had an idea a while ago to write a 1:1 comparison of the examples in Knex's docs with how to do it in Kysely. You can read the unfinished draft in https://github.com/koskimas/kysely/pull/160.

You can use https://github.com/RobinBlomberg/kysely-codegen to help you get started with types.

You're more than welcome to hop on discord and ask anything.

Random side question: is it possible with kysely to simply build a SQL query string but not actually execute it?

Yes! Kysely is primarily a query builder. Execution is just another thing it can do. I've actually submitted a recipe just for that recently, see https://github.com/koskimas/kysely/pull/305

We use RDS Data API, so it wouldn't make sense to use kysely to execute SQL statements.

There's actually a 3rd party Kysely dialect that supports AWS Data API, so you can execute with Kysely. https://github.com/serverless-stack/kysely-data-api

ffxsam commented 1 year ago

Well shoot, I'm already sold by the amazing support! 🤩 I'd love to move away from knex. The lack of type safety can cause some major headaches at times.

I'll dive more into this when I get some spare time. Thank you!