Hey 👋
This one's a banger! 💥 💥 💥
pnpm i kysely@nextWe got $pickTables, $omitTables compile-time helpers to narrow the world view of downstream queries, cutting down on compilation complexity/time while at it!
const results = await db
.$pickTables<'person' | 'pet'>() // <----- now `DB` is only { person: {...}, pet: {...} } for following methods.
.selectFrom('person')
.innerJoin('pet', 'pet.owner_id', 'person.id')
.selectAll()
.execute()
const results = await db
.$omitTables<'toy'>() // <----- now `DB` doesn't have a "toy" table description for following methods.
.selectFrom('person')
.innerJoin('pet', 'pet.owner_id', 'person.id')
.selectAll()
.execute()We got a new ReadonlyKysely<DB> helper type that turns your instance into a compile-time readonly instance!
import { Kysely } from 'kysely'
import type { ReadonlyKysely } from 'kysely/readonly'
export const db = new Kysely<Database>({...}) as never as ReadonlyKysely<Database>
db.selectFrom('person').selectAll() // no problem.
db.selectNoFrom(sql`now()`.as('now')) // no problem.
db.deleteFrom('person') // compilation error + deprecation!
db.insertInto('person').values({...}) // compilation error + deprecation!
db.mergeInto('person')... // compilation error + deprecation!
db.updateTable('person').set('first_name', 'Timmy') // compilation error + deprecation!
sql`...`.execute(db) // compilation error!
// etc. etc.We got a brand new PGlite dialect. With it comes a new supportsMultipleConnections adapter flag that uses a new centralized connection mutex when false - should help simplify all SQLite dialects out here!
import { PGlite } from '@electric-sql/pglite'
import { Kysely, PGliteDialect } from 'kysely'
const db = new Kysely<DB>({
// ...
dialect: new PGliteDialect({
pglite: new PGlite(),
}),
// ...
})We got $narrowType supporting nested narrowing and discriminated unions!
db.selectFrom('person_metadata')
.select(['discriminatedUnionProfile'])
// output type inferred as:
//
// {
// discriminatedUnionProfile: {
// auth:
// | { type: 'token'; token: string }
// | { type: 'session'; session_id: string }
// tags: string[]
// }
// }[]
.$narrowType<{ discriminatedUnionProfile: { auth: { type: 'token' } } }>()
// output type narrowed to:
//
// {
// discriminatedUnionProfile: {
// auth: { type: 'token'; token: string }
// tags: string[]
// }
// }[]
.execute()We got web standards driven query cancellation support. Pass an abort signal to execute* methods and similar. Pick between different inflight query abort strategies - ignore the query, cancel it on the database side or even kill the session on the database side.
// TODO: add example for this featureWe got SafeNullComparisonPlugin to flip (in)equality operators to is and is not when right hand side argument is null.
import { Kysely, SafeNullComparisonPlugin } from 'kysely'
const db = new Kysely<DB>({
// ...
plugins: [new SafeNullComparisonPlugin()],
// ...
})
db.selectFrom('pet')
.where('name', '=', null) // outputs: "name" is null
.where('owner_id', '!=', null) // outputs: "owner_id" is not null
.selectAll()We got a new shouldParse(value, path) option in ParseJSONResultsPlugin for granular control of what gets JSON.parse'd and what stays a string using JSON paths.
import { JSONParseResultsPlugin } from 'kysely'
db.selectFrom('person')
.select((eb) => jsonArrayFrom(
eb.selectFrom('pet')
.where('pet.owner_id', '=', 'person.id')
.selectAll()
).as('pets'))
.withPlugin(new JSONParseResultsPlugin({
shouldParse: (_value, path) => {
if (path.endsWith('.pets')) {
return true
}
return false
}
}))🚀 Features
- feat(utils): Allow explicit undefined in Updateable type (for exactOptionalPropertyTypes support) by @y-hsgw in #1496
- feat(migrator): allow disabling transactions in migrate methods. by @igalklebanov in #1517
- feat: add
thenRefmethod ineb.caseby @ericsodev in #1531 - feat: add
whenRef(lhs, op, rhs)ineb.case. by @iam-abdul in #1598 - feat: add
elseRefineb.case()by @iam-abdul in #1601 - feat: add
$pickTables,$omitTablesand$extendTables, deprecatewithTables. by @igalklebanov in #1582 - feat: add
SafeNullComparisonPluginplugin by @rafaelalmeidatk in #1338 - feat: add more control through configuration @
ParseJSONResultsPlugin. by @igalklebanov in #1453 - feat: allow expressions in create/add index's
columnandcolumnsfunctions, deprecate theirexpressionfunctions. by @igalklebanov in #1664 - feat: add
with(name, query). by @igalklebanov in #1702 - feat: expose migrations from 'kysely/migration'. deprecate migration exports in root. by @igalklebanov in #1618
- refactor: bump minimum TypeScript version to 4.7. by @igalklebanov in #1696
- refactor: bump minimum TypeScript version to 4.8. by @igalklebanov in #1756
- refactor: bump minimum TypeScript version to 4.9. by @igalklebanov in #1759
- refactor: bump minimum TypeScript version to 5.0. by @igalklebanov in #1761
- refactor: bump minimum TypeScript version to 5.1. by @igalklebanov in #1770
- refactor: bump minimum TypeScript version to 5.2. by @igalklebanov in #1771
- refactor: bump minimum TypeScript version to 5.3. by @igalklebanov in #1772
- refactor: bump minimum TypeScript version to 5.4. by @igalklebanov in #1773
- feat: support narrowing by deep object keys in
NarrowPartialby @ethanresnick in #1667 - feat: add
ReadonlyKysely<DB>helper. by @igalklebanov in #218 - refactor: replace
requireAllProps<T>(obj)usage withsatisfies AllProps<T>. by @igalklebanov in #1787 - feat: allow overriding file import function @
FileMigrationProvider. by @igalklebanov in #1661 - feat: query cancellation. by @igalklebanov in #1796 & #1797 & #1798 & 33e60df & b739e02 & 4d7064f
PostgreSQL 🐘 / MySQL 🐬
- feat(Introspect): add support for postgres & mysql foreign tables by @williamluke4 in #1494
PostgreSQL 🐘 / MSSQL 🥅
- feat(Migrator): allow passing transactions to
Migrator. by @jlucaso1 in #1480 - feat: support IF EXISTS in DROP COLUMN by @shuaixr in #1692
PostgreSQL 🐘
- feat: support dropping multiple types with schema.dropType(), cascade. by @aantia in #1516
- feat: add alter type query support. by @lucianolix in #1363
MySQL 🐬
- feat: allow expressions in unique constraint by @ericsodev in #1518
- feat: Add support for dropping temporary tables with temporary() modifier by @szalonna in #1615
- feat: add
addIndextoCreateTableBuilderby @alenap93 in #1352
MSSQL 🥅
- feat: add
datetime2data type support. by @igalklebanov in #1792
PGlite 🟨
- feat: add PGlite dialect. by @igalklebanov in #1510
🐞 Bugfixes
📖 Documentation
- docs(returning): remove outdated SQLite alias workaround by @aymenhmaidiwastaken in #1793
📦 CICD & Tooling
- chore: improve TypeScript benchmarks. by @igalklebanov in #1757
- chore: add returning.bench.ts by @igalklebanov in 65b6ec4
- chore: enhance returning benchmarks. by @igalklebanov in b23085a
- chore: add selectNoFrom benchmarks. @igalklebanov in 8193d37
- test: fix TypeScript 5.4.0 test following target bump to es2023. by @igalklebanov in #1780
- chore: drop CommonJS distribution. by @igalklebanov in #1782
- chore(ci): support rc publishes from next branch. by @igalklebanov in 585bf60
⚠️ Breaking Changes
-
Migrator,FileMigrationProviderand other migration related things are now exported from'kysely/migration'. Importing from'kysely'will provide an informative error message at compilation time.-import { Migrator, FileMigrationProvider } from 'kysely' +import { Migrator, FileMigrationProvider } from 'kysely/migration'
-
Minimum TypeScript version is now 5.4. Versions 5.3 and older will get a very aggressive compilation error.
-
The library no longer ships CommonJS files. Use a Node.js version that supports
require(esm), or use dynamic imports. ES Modules files have moved from/dist/esm/to/dist/.
🐤 New Contributors
- @y-hsgw made their first contribution in #1496
- @williamluke4 made their first contribution in #1494
- @ericsodev made their first contribution in #1518
- @aantia made their first contribution in #1516
- @iam-abdul made their first contribution in #1598
- @szalonna made their first contribution in #1615
- @rafaelalmeidatk made their first contribution in #1338
- @jlucaso1 made their first contribution in #1480
- @lucianolix made their first contribution in #1363
- @shuaixr made their first contribution in #1692
- @aymenhmaidiwastaken made their first contribution in #1793
Full Changelog: v0.28.16...v0.29.0-rc.0