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.2
Name Modified Size InfoDownloads / Week
Parent folder
0.28.2 source code.tar.gz 2025-04-24 17.1 MB
0.28.2 source code.zip 2025-04-24 17.4 MB
README.md 2025-04-24 2.2 kB
Totals: 3 Items   34.5 MB 0

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:

:::ts
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:

:::ts
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

๐Ÿž Bugfixes

SQLite ๐Ÿ“˜

๐Ÿ“– Documentation

๐Ÿ“ฆ CICD & Tooling

โš ๏ธ Breaking Changes

๐Ÿค New Contributors

Full Changelog: https://github.com/kysely-org/kysely/compare/0.28.1...0.28.2

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