Skip to content

Releases: kysely-org/kysely

0.29.0-rc.0

24 Apr 20:13
Immutable release. Only release title and notes can be modified.
v0.29.0-rc.0
38dbd88

Choose a tag to compare

0.29.0-rc.0 Pre-release
Pre-release

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.

  import { Kysely, PostgresDialect } from 'kysely'
  import { Client, ... } from 'pg'

  const db = new Kysely<Database>({
    dialect: new PostgresDialect({
      // ...
      controlClient: Client, // optional, for out-of-pool connections for database side query aborts.
      // ...
    })
  })

  const options = { signal: AbortSignal.timeout(3_000) } // throw abort/timeout errors and ignore query reuslts

  query.execute(options)
  query.stream(options)
  sql`...`.execute(db, options)
  db.executeQuery(compiledQuery, options)
  // etc. etc.

  query.execute({ ...options, inflightQueryAbortStrategy: 'cancel query' }) // also cancel query database side
  query.execute({ ...options, inflightQueryAbortStrategy: 'kill session' }) // also kill session database side

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) => {
      // parse only the pets array
      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

Read more

0.28.16

10 Apr 18:07
Immutable release. Only release title and notes can be modified.
v0.28.16
b4566a1

Choose a tag to compare

Hey 👋

A small batch of bug fixes. Please report any issues. 🤞😰🤞

0.29 is getting closer btw. 🌶️

🚀 Features

🐞 Bugfixes

  • fix: FilterObject allows any defined value when query context has no tables (TB is never). by @igalklebanov in #1791

📖 Documentation

📦 CICD & Tooling

⚠️ Breaking Changes

🐤 New Contributors

What's Changed

Full Changelog: v0.28.15...v0.28.16

0.28.15

31 Mar 01:49
Immutable release. Only release title and notes can be modified.
v0.28.15
87fe239

Choose a tag to compare

Hey 👋

The introduction of dehydration in JSON functions/helpers caused an unexpected bug for consumers that have some columns defined as '${number}', e.g. '1' | '2' (also when wrapped in ColumnType or similar). Such columns, when participating in a JSON function/helper would dehydrate to number instead of staying as string.

Why dehydrate numeric strings to numbers in the first place? Select types in kysely describe the data after underlying driver's (e.g. pg) data transformation. Some drivers transform numeric columns to strings to be safe. When these columns participate in JSON functions, they lose original column data types - drivers don't know they need to transform to string - they return as-is.

This release introduces a special helper type that wraps your column type definition and tells kysely to NOT dehydrate it in JSON functions/helpers.

import type { NonDehydrateable } from 'kysely'

interface Database {
  my_table: {
    a_column: '1' | '2' | '3', // dehydrates to `number`
    another_column: NonDehydrateable<'1' | '2' | '3'>, // stays `'1' | '2' | '3'`
    column_too: NonDehydrateable<ColumnType<'1' | '2' | '3'>> // stays `'1' | '2' | '3'`
  }
}

🚀 Features

  • feat: add NonDehydrateable<T> to allow opt-out from dehydration in JSON functions/helpers. by @igalklebanov in #1697

🐞 Bugfixes

PostgreSQL 🐘

📖 Documentation

📦 CICD & Tooling

⚠️ Breaking Changes

🐤 New Contributors

Full Changelog: v0.28.14...v0.28.15

0.28.14

20 Mar 11:28
Immutable release. Only release title and notes can be modified.
v0.28.14
91cf373

Choose a tag to compare

Hey 👋

A small batch of bug fixes. Please report any issues. 🤞😰🤞

🚀 Features

🐞 Bugfixes

MySQL 🐬

📖 Documentation

📦 CICD & Tooling

⚠️ Breaking Changes

🐤 New Contributors

Full Changelog: v0.28.13...v0.28.14

0.28.13

18 Mar 22:12
Immutable release. Only release title and notes can be modified.
v0.28.13
b15c041

Choose a tag to compare

Hey 👋

A small batch of bug fixes. Please report any issues. 🤞😰🤞

🚀 Features

🐞 Bugfixes

  • fix: missing sideEffects: false in root package.json resulting in bigger bundles in various bundlers. by @igalklebanov in #1746
  • fix: Insertable allows non-objects when a table has no required columns. by @igalklebanov in #1747

PostgreSQL 🐘

  • fix: ON COMMIT clause not being output when using .as(query) in CREATE TABLE queries. by @igalklebanov in #1748

📖 Documentation

📦 CICD & Tooling

⚠️ Breaking Changes

🐤 New Contributors

Full Changelog: v0.28.12...v0.28.13

0.28.12

14 Mar 09:13
Immutable release. Only release title and notes can be modified.
v0.28.12
afc81a1

Choose a tag to compare

Hey 👋

A small batch of bug fixes. Please report any issues. 🤞😰🤞

🚀 Features

🐞 Bugfixes

MySQL 🐬

📖 Documentation

📦 CICD & Tooling

⚠️ Breaking Changes

🐤 New Contributors

Full Changelog: v0.28.11...v0.28.12

0.28.11

31 Jan 18:58
Immutable release. Only release title and notes can be modified.
v0.28.11
102d477

Choose a tag to compare

Hey 👋

A small batch of bug fixes. Please report any issues. 🤞😰🤞

🚀 Features

🐞 Bugfixes

  • Prevent re-use of finished trx outside callback by @jacobpgn in #1694

SQLite 📘

  • returning needs to come before order by in sqlite for an update..where query. by @hwisu in #1691

📖 Documentation

📦 CICD & Tooling

⚠️ Breaking Changes

🐤 New Contributors

Full Changelog: v0.28.10...v0.28.11

0.28.10

18 Jan 07:13
Immutable release. Only release title and notes can be modified.
v0.28.10
09275f3

Choose a tag to compare

Hey 👋

A small batch of bug fixes. Please report any issues. 🤞😰🤞

🚀 Features

🐞 Bugfixes

  • Add ExtractColumnType and DrainOuterGeneric type exports by @mifi in #1679
  • fix: $narrowType compilation errors when composite: true. by @igalklebanov in #1681
  • fix: executeTakeFirst compilation error when composite. by @igalklebanov in #1683
  • fix: with/withRecursive compilation errors when composite. by @igalklebanov in #1684

PostgreSQL 🐘 / MSSQL 🥅

  • fix: Migrator attempts to create custom migration schema even if it exists and fails on dialects that don't support if not exists. by @austin-hall-skylight in #1608

PostgreSQL 🐘 / SQLite 📘

📖 Documentation

📦 CICD & Tooling

⚠️ Breaking Changes

🐤 New Contributors

Full Changelog: v0.28.9...v0.28.10

0.28.9

13 Dec 17:48
Immutable release. Only release title and notes can be modified.
v0.28.9
44e578d

Choose a tag to compare

Hey 👋

A small batch of bug fixes. Please report any issues. 🤞😰🤞

🚀 Features

🐞 Bugfixes

PostgreSQL 🐘

  • fix: withSchema not applying for delete query using clause. by @igalklebanov in #1648
  • fix: withSchema adds schema to for update|share|key share|no key share of tables causing database errors. by @igalklebanov in #1659

📖 Documentation

📦 CICD & Tooling

⚠️ Breaking Changes

🐤 New Contributors

Full Changelog: v0.28.8...v0.28.9

0.28.8

09 Oct 21:47
v0.28.8
4daed49

Choose a tag to compare

Hey 👋

A small batch of bug fixes. Please report any issues. 🤞😰🤞

🚀 Features

🐞 Bugfixes

PostgreSQL 🐘

  • fix: filter schemas the current user does not have access to in postres introspector by @chanon in #1550
  • fix: insert/update not being wrapped in parens when in CTE of a merge query. by @igalklebanov & @msifd in #1611

📖 Documentation

📦 CICD & Tooling

⚠️ Breaking Changes

🐤 New Contributors

Full Changelog: v0.28.7...v0.28.8