github kysely-org/kysely v0.29.0-rc.0
0.29.0-rc.0

pre-release9 hours ago

Hey 👋

This one's a banger! 💥 💥 💥

pnpm i kysely@next

We 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 feature

We 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

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 addIndex to CreateTableBuilder by @alenap93 in #1352

MSSQL 🥅

PGlite 🟨

🐞 Bugfixes

📖 Documentation

📦 CICD & Tooling

⚠️ Breaking Changes

  • Migrator, FileMigrationProvider and 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

Full Changelog: v0.28.16...v0.29.0-rc.0

Don't miss a new kysely release

NewReleases is sending notifications on new releases.