kysely icon indicating copy to clipboard operation
kysely copied to clipboard

make `SchemaModule` optional and injectable.

Open igalklebanov opened this issue 2 years ago • 4 comments

This PR makes SchemaModule optional and injectable when instantiating Kysely. If not injected and consumer tries accessing it, a runtime error is thrown.

99% of the time, DDL queries are executed in migrations.

A considerable chunk of our consumers use Kysely in serverless/edge/browser environments. 99% of the time only DML queries are being executed there. In such environments bundle sizes affect cold starts / load times. The bigger the bundle, the worse our consumers' user experience.

Builder pattern is great for DX, but is bad for tree-shaking. By making SchemaModule injectable and optionally supported, we help decrease our consumers bundle sizes and help them ship better user experiences.

Things considered but not done:

  • export SchemaModule & builders from kysely/schema instead of kysely. Unlike helpers, SchemaModule belongs in "main" Kysely.
  • make db.schema return type never if no SchemaModule was passed @ config. Compilation performance hit that's not worth it.

Todo:

  • [ ] check bundle size without SchemaModule usage.

igalklebanov avatar May 04 '23 22:05 igalklebanov

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
kysely ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 6, 2023 8:40am

vercel[bot] avatar May 04 '23 22:05 vercel[bot]

This feels kinda weird. Should we instead make it completely separate. Something like:

const schema = new Schema(db)

and remove db.schema? Having it in db.schema is just a remnant from the "let's look a lot like knex" days.

koskimas avatar May 05 '23 06:05 koskimas

This is definitely weird, and your suggestion definitely removes that weirdness. 👏
At the same time, we need to make sure our consumers, who might already have a bunch of migration files, don't get hurt by this.

igalklebanov avatar May 05 '23 07:05 igalklebanov

Yeah we'd definitely need to first deprecate the current API and and so on. Not just break everything. But I think your suggestion is just too much of a hack to be a permanent part of the API. Is the saving in bundle size significant enough to justify this change in the first place?

koskimas avatar May 08 '23 05:05 koskimas

Closing this as it smells by now. Might re-attempt something in the future.

igalklebanov avatar Apr 21 '24 10:04 igalklebanov