Download Latest Version 0.28.3 source code.tar.gz (17.1 MB)
Email in envelope

Get an email when there's a new version of Kysely SQL

Home / 0.28.0
Name Modified Size InfoDownloads / Week
Parent folder
0.28.0 source code.tar.gz 2025-04-13 17.1 MB
0.28.0 source code.zip 2025-04-13 17.4 MB
README.md 2025-04-13 10.1 kB
Totals: 3 Items   34.5 MB 0

Hey πŸ‘‹

Transactions are getting a lot of love in this one!

As part an effort to replace Knex with Kysely, B4nan, the author of mikro-orm drove the new setAccessMode('read only'|'read write') method when starting transactions.

You can now commit/rollback transactions manually and there's even savepoint support:

:::ts
const trx = await db.startTransaction().execute()

try {
  // do stuff with `trx`, including work with savepoints via the new `savepoint(name)`, `rollbackToSavepoint(name)` and `releaseSavepoint(name)` methods!

  await trx.commit().execute()
} catch (error) {
  await trx.rollback().execute()

  throw error
}

We also added using keyword support, so now you can write:

:::ts
await using db = new Kysely({...})

and db.destroy() will be called automatically once the current scope is exited. If you plan on trying this out (it is optional, you can still const db = new Kysely({...}) and await db.destroy() manually), the using keyword requires typescript >= 5.2 and the following tsconfig.json options:

:::ts
{
  "compilerOptions": {
    "target": "ES2022",
    "lib": ["ESNext", ...],
    ...
  }
  ...
}

We also added a plugin to handle in () and not in (). It comes with 2 handling strategies, one similar to how Knex.js, PrismaORM, Laravel and SQLAlchemy do it, and one similar to how TypeORM and Sequelize do it. It also supports custom strategies, e.g. throwing an error to avoid making a call to the database and wasting resources. Here's an example with one of the strategies we ship:

:::ts
import {
  // ...
  HandleEmptyInListsPlugin,
  // ...
  replaceWithNoncontingentExpression,
  // ...
} from 'kysely'

const db = new Kysely<Database>({
  // ...
  plugins: [
    new HandleEmptyInListsPlugin({
      strategy: replaceWithNoncontingentExpression
    })
  ],
})

// ...
  .where('id', 'in', [])
  .where('first_name', 'not in', []) // => `where 1 = 0 and 1 = 1`

πŸš€ Features

PostgreSQL 🐘 / MySQL 🐬
PostgreSQL 🐘 / MS SQL Server πŸ₯…
PostgreSQL 🐘 / SQLite πŸ“˜
PostgreSQL 🐘
MySQL 🐬
MS SQL Server πŸ₯…
SQLite πŸ“˜

🐞 Bugfixes

PostgreSQL 🐘

πŸ“– Documentation

πŸ“¦ CICD & Tooling

⚠️ Breaking Changes

  • InferResult now outputs InsertResult[], UpdateResult[], DeleteResult[], MergeResult[], instead of InsertResult, UpdateResult, DeleteResult, MergeResult. To get the singular form, use type Result = InferResult<T>[number].
  • Some generic/wide usages of QueryCreator's methods should no longer pass type checks. We never supported these officially.
  • As preventAwait is now removed on all builders, you must avoid awaiting builders without calling execute-like methods on your own.
  • TypeScript versions 4.5 and older are no longer supported. You will get an immediate compilation error telling you to upgrade.
  • QueryResult.numUpdatedOrDeletedRows has been removed (after spending ~2 years in deprecation). We still log a warning. Outdated dialects that don't use QueryResult.numAffectedRows should be updated OR forked.
  • DefaultQueryExecutor.compileQuery now requires passing a queryId argument. Use the newly exported createQueryId() as that argument value from now on.
  • UpdateValuesNode type has been removed.
  • MssqlDialectConfig.tedious.resetConnectionOnRelease has been deprecated, and had it's default flipped to false. Use MssqlDialectConfig.resetConnectionsOnRelease instead.
  • MssqlDialectConfig.tarn.options.validateConnections has been deprecated. Use MssqlDialectConfig.validateConnections instead.
  • String literals are now ' injection protected, hopefully. Please report any issues.

🐀 New Contributors

Full Changelog: https://github.com/kysely-org/kysely/compare/0.27.6...0.28.0

Source: README.md, updated 2025-04-13