Skip to content

Releases: kysely-org/kysely

0.28.2

24 Apr 10:32
Compare
Choose a tag to compare

Hey πŸ‘‹

v0.28 broke an undocumented TypeScript behavior our API had that allowed you to pass table name unions to query builders and enable some DRYing of queries. Seeing that this pattern was quite popular, we decided to support it officially with the addition of the table method in the dynamic module.

You can pull off some crazy complex stuff like:

async function getRowByColumn<
  T extends keyof Database,
  C extends keyof Database[T] & string,
  V extends SelectType<Database[T][C]>,
>(t: T, c: C, v: V) {
  // We need to use the dynamic module since the table name
  // is not known at compile time.
  const { table, ref } = db.dynamic

  return await db
    .selectFrom(table(t).as('t'))
    .selectAll()
    .where(ref(c), '=', v)
    // `id` can be directly referenced since every table has it.
    .orderBy('t.id')
    .executeTakeFirstOrThrow()
}

const person = await getRowByColumn('person', 'first_name', 'Arnold')

...and it'll narrow the downstream query context to the intersection of all the possible shapes of tables in the union type. (DONT DO THIS AT HOME KIDS!)

A simpler example would be:

async function deleteItem(id: string, table: 'person' | 'pet') {
  await db
    .deleteFrom(db.dynamic.table(table).as('t'))
    .where('id', '=', id)
    .executeTakeFirstOrThrow()
}

If you attempt to refer to a column that doesn't exist in both "person" and "pet" (e.g. "pet"'s "species" column), the compiler will correctly yell at you.

πŸš€ Features

  • Add table to DynamicModule for dynamic table references by @koskimas in #1434

🐞 Bugfixes

SQLite πŸ“˜
  • fix: SQLite's introspector is printing deprecation errors for orderBy(array). by @igalklebanov in #1435

πŸ“– Documentation

πŸ“¦ CICD & Tooling

⚠️ Breaking Changes

🐀 New Contributors

Full Changelog: 0.28.1...0.28.2

0.28.1

19 Apr 10:41
Compare
Choose a tag to compare

Hey πŸ‘‹

Just a small crucial bug fix release. Please inform us if you see any more regressions since v0.28. πŸ™

πŸš€ Features

🐞 Bugfixes

PostgreSQL 🐘
  • pg introspector - Wrap schema.table in double quotes for case handling by @neil176 in #1426

πŸ“– Documentation

πŸ“¦ CICD & Tooling

⚠️ Breaking Changes

🐀 New Contributors

Full Changelog: 0.28.0...0.28.1

0.28.0

13 Apr 05:52
Compare
Choose a tag to compare

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:

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:

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:

{
  "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:

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 🐬
  • feat: Allow read-only transactions in Postgres and MySQL by B4nan in #1342 & #1350
PostgreSQL 🐘 / MS SQL Server πŸ₯…
  • Add within group clause support for aggregate function builder by @ivashog in #1024
PostgreSQL 🐘 / SQLite πŸ“˜
PostgreSQL 🐘
MySQL 🐬
MS SQL Server πŸ₯…
  • Add outer and cross apply (mssql) by @drew-marsh in #1074
  • refactor: extract validateConnections and resetConnectionsOnRelease to root of config, flip default resetConnectionsOnRelease behavior. by @igalklebanov in #1388
SQLite πŸ“˜

🐞 Bugfixes

PostgreSQL 🐘
  • fix: postgres auto increment introspection is wrong after column renames. by @igalklebanov in #1391

πŸ“– 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: 0.27.6...0.28.0

0.27.6

03 Mar 18:38
Compare
Choose a tag to compare

Hey πŸ‘‹

v0.28 is right around the corner! πŸ‘€

πŸš€ Features

🐞 Bugfixes

  • fix: implements a underscore validation to camelcase plugin by @rhyzzor in #1290
  • fix: resolve edge case with varying shapes in multiple item inserts causing undefined in parameters. by @naorpeled & @igalklebanov in #1311
PostgreSQL 🐘
  • Use JS sort method to sort migrations by name by @DavesBorges in #844
  • fix: WithSchemaPlugin is adding schema to table function arguments and causes db errors in json_agg and to_json. by @igalklebanov in #827
SQLite πŸ“˜

πŸ“– Documentation

PostgreSQL 🐘

πŸ“¦ CICD & Tooling

⚠️ Breaking Changes

🐀 New Contributors

Full Changelog: 0.27.5...0.27.6

0.27.5

08 Dec 12:05
Compare
Choose a tag to compare

Hey πŸ‘‹

Long-time community member and ambassador @thelinuxlich has joined the contributors club! πŸ…

v0.28 is right around the corner! πŸ‘€

πŸš€ Features

PostgreSQL 🐘 / MySQL 🐬 / SQLite πŸ“˜
  • Add orderBy clause support to aggregate function builder by @ivashog in #896
PostgreSQL 🐘 / MySQL 🐬
  • Adds onReserveConnection to Postgres and MySQL dialect configs by @dcousineau in #996
PostgreSQL 🐘
MS SQL Server πŸ₯…
  • Add additional config options to MSSQL dialect by @tmrclark in #1073

🐞 Bugfixes

  • Updated TraversedJSONPathBuilder.$castTo and .$notNull to support chaining with .as() by @cassus in #1139
  • DeduplicateJoinsPlugin preserves order of joins by @sam-lewis-storyteq in #1156

πŸ“– Documentation

πŸ“¦ CICD & Tooling

⚠️ Breaking Changes

🐀 New Contributors

Full Changelog: 0.27.4...0.27.5

0.27.4

06 Jul 23:35
Compare
Choose a tag to compare

Hey πŸ‘‹

We've reached 100 contributors AND 1,000 pull requests since our last release! 🍾
Here's all the amazing work done since version 0.27.3...

πŸš€ Features

  • Added clearGroupBy() by @dswbx in #921
  • add objectStrategy option that allows to not mutate result objects/arrays @ ParseJSONResultsPlugin. by @igalklebanov in #953
PostgreSQL 🐘 / SQLite πŸ“˜
  • Support table names in UpdateQueryBuilder.returningAll by @koskimas in f63327e
MySQL 🐬 / MS SQL Server πŸ₯…
PostgreSQL 🐘
MS SQL Server πŸ₯…

🐞 Bugfixes

  • move preventAwait to alter-column-builder.ts. by @igalklebanov in #1031
  • fixes The type of eb in selectFrom(eb => ...) is wrong by @koskimas in 873671b
  • fixes QueryCompilerError: Could not serialize value causes Kysely instance to fail later by @koskimas in a65a7f3
  • fixes CamelCasePlugin messes up complex type mappings with setTypeParser by @koskimas in d45a8fa
PostgreSQL 🐘 / MS SQL Server πŸ₯…
PostgreSQL 🐘
MS SQL Server πŸ₯…

πŸ“– Documentation

πŸ“¦ CICD & Tooling

⚠️ Breaking Changes

🐀 New Contributors

Full Changelog: 0.27.3...0.27.4

0.27.3

27 Apr 12:59
Compare
Choose a tag to compare

Hey πŸ‘‹

This release happened on 03/09/2024.

What's Changed

  • add cast method to ExpressionBuilder. by @koskimas in 3df726f
  • fix bug in ExtractTableAlias exposed by TypeScript 5.4. by @koskimas in e356951
  • add MERGE query support. by @igalklebanov in #700
  • introspect column comments by @maktouch in #842
  • Fix MSSQL Table Introspection Duplicate Column by @timclark97 in #848
  • implement additional query builder clear methods by @garymathews in #840
  • Just add missing smallint support for addColumn() (SIMPLE_COLUMN_DATA_TYPES) by @hash0000 in #860
  • Correct spelling mistake in the case example by @obax in #878
  • [Docs] Update complex join example to better illustrate the options available (symmetry with where) by @MarkusWendorf in #883
  • add IDENTITY column support. by @igalklebanov in #823
  • Add LIMIT operator for update statements by @tbui17 in #885
  • add FETCH clause support. by @igalklebanov in #822
  • add TOP clause support. by @igalklebanov in #821

Breaking Changes:

  • into is now optional in InsertQueryNode.
  • table is now optional in UpdateQueryNode.
  • column data types are now validated at runtime. This only affects users who passed unsupported strings in the past. In case Kysely doesn't offer built-in support for a specific data type, you should have then and still should use sql template tag.

New Contributors

  • @maktouch made their first contribution in #842
  • @timclark97 made their first contribution in #848
  • @garymathews made their first contribution in #840
  • @hash0000 made their first contribution in #860
  • @obax made their first contribution in #878
  • @tbui17 made their first contribution in #885

Full Changelog: 0.27.2...0.27.3

0.27.2

06 Jan 10:27
Compare
Choose a tag to compare
  • Add allowUnorderedMigrations option for the migrator. #723 Awesome work by @tracehelms ❀️
  • Fix update and insert query type issues when using Kysely<any>.
  • Improve error messages when passing a wrong column name or wrong type for a column in UpdateQueryBuilder#set and InsertQueryBuilder#values methods.

0.27.1

02 Jan 10:52
Compare
Choose a tag to compare
  • Add $notNull type helper
  • Support for update of table and friends #683
  • Support insert into "person" default values #685
  • Support arbitrary expressions in limit and offset
  • Support insert, update and delete queries in raw SQL substitutions #680
  • Fix node 14 regression #824
  • Fix fn.agg regression where two type arguments were required #829

0.27.0

30 Dec 12:14
Compare
Choose a tag to compare
  • Add mssql dialect. A huge effort by @igalklebanov ❀️ #595
  • Add postgres json_agg and to_json functions to function module
  • Add is distinct from operator #673
  • Add set('first_name', 'Jennifer') variant for update query's set method #672
  • Add as statement support for createTable #771. Thank you @viraxslot ❀️
  • Add nulls not distinct option for constraints #770. Thank you @viraxslot ❀️
  • Add addIndex & dropIndex @ AlterTableBuilder #720. Thank you @Gaspero
  • Add stream() support for sqlite dialect #754. Thank you @tgriesser ❀️
  • Fix query and error logging both occur on error. #796. Thank you @igalklebanov ❀️
  • Fix type issue with $if #793. Thank you @igalklebanov ❀️
  • Fix issue where onConflict..doUpdateSet used select types instead of update types. #792. Thank you @igalklebanov ❀️
  • Add eb.jsonPath<$> #791. Thank you @igalklebanov ❀️
  • $narrowType supports new type tag NotNull for an easier way to mark columns not nullable manually
  • Fix #811
  • Support arbitrary expressions in min and max aggregate functions.

Breaking changes

  • selectNoFrom is removed from ExpressionBuilder due to severe typescript performance issues. selectNoFrom still exists in the Kysely instance, and in most cases, you can use that instead. See this example on how to migrate: https://kyse.link/?p=s&i=sqAZIvTQktxgXYzHGkqX.
  • Types are once again a little bit stricter in some places. You might get type errors from code like where('first_name', '=', sql`something`). You need to explicitly give a type for sql expressions like this sql<string>`something`
  • Deprecated functions eb.cmpr and eb.bxp have been removed. Use eb as a function instead.