kysely
kysely copied to clipboard
make `SchemaModule` optional and injectable.
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 fromkysely/schemainstead ofkysely. Unlike helpers,SchemaModulebelongs in "main" Kysely. - make
db.schemareturn typeneverif noSchemaModulewas passed @ config. Compilation performance hit that's not worth it.
Todo:
- [ ] check bundle size without
SchemaModuleusage.
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 |
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.
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.
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?
Closing this as it smells by now. Might re-attempt something in the future.