Releases: kysely-org/kysely
0.28.2
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
π 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
Hey π
Just a small crucial bug fix release. Please inform us if you see any more regressions since v0.28. π
π Features
π Bugfixes
PostgreSQL π
π Documentation
π¦ CICD & Tooling
β οΈ Breaking Changes
π€ New Contributors
Full Changelog: 0.28.0...0.28.1
0.28.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:
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
InferResult
should output plural. by @igalklebanov in #1064- Speedup types with huge databases. Fixes #867 by @koskimas in #1080
- implement missing expression features by @koskimas in #1085
- Remove preventAwait by @wirekang in #1160
- add
ControlledTransaction
. by @igalklebanov in #962 & #1193 await using kysely = new Kysely()
support. by @igalklebanov in #1167- feat: add HandleEmtpyInListsPlugin. by @austinwoon and @igalklebanov in #925
- Add Date as a valid return type for max and min by @samclearman & @igalklebanov in #1062
- Add support for cross join and cross join lateral by @ersinakinci in #1325
- dry up joins. by @igalklebanov in c95f499
- revisiting orderBy - deprecations, new order by item builder (nullFirst(), nullsLast(), collate()). by @igalklebanov in #1326
- add
queryId
toCompiledQuery
and all transformer methods. by @igalklebanov in #176 - feat: Add disableTransactions option to Migrator by @reidswan in #1335
- Redundant export UpdateValuesNode removed by @Ciantic in #1379
- Fix ctrl transaction mutation issues by @koskimas in #1406
- feat: escape single quotes in string literals. by @igalklebanov in #1392
PostgreSQL π / MySQL π¬
PostgreSQL π / MS SQL Server π₯
PostgreSQL π / SQLite π
PostgreSQL π
- feat: support refresh materialized view by @QuentinJanuel in #990
- add
returning
support inMERGE
queries. by @igalklebanov in #1171 - Support json_agg(column_ref) by @SimonSimCity in #1316
- feat: expands limit in select accepting null value by @alenap93 in #1347
- feat: make create type as enum values argument readonly. by @igalklebanov in #1390
- add support for constraint renaming. by @koskimas in #1408
MySQL π¬
MS SQL Server π₯
- Add outer and cross apply (mssql) by @drew-marsh in #1074
- refactor: extract
validateConnections
andresetConnectionsOnRelease
to root of config, flip defaultresetConnectionsOnRelease
behavior. by @igalklebanov in #1388
SQLite π
- SQLite's OR CONFLICT clause for inserts by @vincentiusvin & @igalklebanov in #976
π Bugfixes
- fix: no logging in streams. by @igalklebanov in #1382
- fix: ImmediateValueTransformer not handling PrimitiveValueListNodes. by @igalklebanov in #1396
- fix: allow empty array for sql.join by @Sealos in #1395
PostgreSQL π
- fix: postgres auto increment introspection is wrong after column renames. by @igalklebanov in #1391
π Documentation
- add reusable helpers recipe by @koskimas in #1085
- fix jsdocs. by @igalklebanov in 1c5e03a
π¦ CICD & Tooling
- ci: run 22.x by @igalklebanov in 9736aeb
- chore: enforce min TS version by @igalklebanov in #1194
- fix package-lock. by @igalklebanov in f348dfb
- add TypeScript benchmarks. by @igalklebanov in #1314
- improve join tests dialect coverage. by @igalklebanov in 6eaf754
- minor ci tweaks. by @igalklebanov in ca11632
β οΈ Breaking Changes
InferResult
now outputsInsertResult[]
,UpdateResult[]
,DeleteResult[]
,MergeResult[]
, instead ofInsertResult
,UpdateResult
,DeleteResult
,MergeResult
. To get the singular form, usetype 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 callingexecute
-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 useQueryResult.numAffectedRows
should be updated OR forked.DefaultQueryExecutor.compileQuery
now requires passing aqueryId
argument. Use the newly exportedcreateQueryId()
as that argument value from now on.UpdateValuesNode
type has been removed.MssqlDialectConfig.tedious.resetConnectionOnRelease
has been deprecated, and had it's default flipped tofalse
. UseMssqlDialectConfig.resetConnectionsOnRelease
instead.MssqlDialectConfig.tarn.options.validateConnections
has been deprecated. UseMssqlDialectConfig.validateConnections
instead.- String literals are now
'
injection protected, hopefully. Please report any issues.
π€ New Contributors
- @QuentinJanuel made their first contribution in #990
- @austinwoon made their first contribution in #925
- @samclearman made their first contribution in #1062
- @drew-marsh made their first contribution in #1074
- @SimonSimCity made their first contribution in #1316
- @ersinakinci made their first contribution in #1325
- @reidswan made their first contribution in #1335
- @B4nan made their first contribution in #1342
- @Ciantic made their first contribution in #1379
- @Sealos made their first contribution in #1395
Full Changelog: 0.27.6...0.28.0
0.27.6
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 π
- fix: isAutoIncrementing: true for sqlite integer primary key by @tgriesser in #1344 and #1349
π Documentation
- Update CONTRIBUTING.md by @igalklebanov in bfbd002
- badge stuff @ README.md by @igalklebanov in 541c935
- add CODE_OF_CONDUCT.md by @igalklebanov in #564
- add another example to CoC. by @igalklebanov in 9ba0f02
- explain examples in CoC. by @igalklebanov in 708afad
- add example to CoC. by @igalklebanov in 1ba5586
- add examples to CoC. by @igalklebanov in 1cbe9b5
- CoC wording. by @igalklebanov in 5598338
- add reactions as an example in CoC. by @igalklebanov in 67e413e
- Add a reference to ref in table's docstring by @AlexErrant in #1315
- add FUNDING.md by @igalklebanov in #1317
- Update _prerequisites.mdx by @igalklebanov in bd167d3
- fix minor typo in raw-builder/sql by @austin-tildei in #1346
- fix(docs): Fixed closing backtick in Migrator JSDoc by @nick-w-nick in #1348
- remove X links. by @igalklebanov in 4870549 and deedd28
- add Marvin's (Deno) quote. by @igalklebanov in #1360
- Add Oracle dialect to dialects.md by @JosephTuffin in #1371
PostgreSQL π
π¦ CICD & Tooling
β οΈ Breaking Changes
π€ New Contributors
- @rhyzzor made their first contribution in #1290
- @AlexErrant made their first contribution in #1315
- @czeidler made their first contribution in #1319
- @austin-tildei made their first contribution in #1346
- @JosephTuffin made their first contribution in #1371
Full Changelog: 0.27.5...0.27.6
0.27.5
Hey π
Long-time community member and ambassador @thelinuxlich has joined the contributors club! π
v0.28 is right around the corner! π
π Features
- add modifyEnd to insert, update and delete query builders by @thelinuxlich in #871
PostgreSQL π / MySQL π¬ / SQLite π
PostgreSQL π / MySQL π¬
- Adds
onReserveConnection
to Postgres and MySQL dialect configs by @dcousineau in #996
PostgreSQL π
MS SQL Server π₯
π 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
- Migrate to new playground by @wirekang in #861
- Improve relations recipe by @koskimas in #1081
- Improve expressions recipe by @koskimas in #1083
- fix: References typo by @Alcas1 in #1092
- Fix docs for
generatedAlwaysAs
by @nikeee in #1113 - chore: fix some comments by @timesince in #1114
- added clickhouse and bigquery dialects by @maktouch in #1117
- docs: updated outdated links by @krijoh92 in #1125
- Update migrations.mdx by @tijptjik in #1122
- fix: Raw builder typos by @Alcas1 in #1148
- docs: support light mode. by @igalklebanov in #1177
- docs: fix weird default state showing dark and light elements. by @igalklebanov in #1179
- fix(docs): add missing import to migrations example script by @mxkxf in #1178
- docs: refresh quotes. by @igalklebanov in #1182
- docs: fix stackblitz theme out of sync. by @igalklebanov in #1183
- docs: rework features list. by @igalklebanov in #1185
- docs:
MERGE
examples by @igalklebanov in #1188 - docs: add prerequisites section in "getting started". by @igalklebanov in #1197
- Docs: fix typo by @remiposo in #1216
- chore: check jsdoc examples. by @igalklebanov in #1263
- chore: fix jsdoc errors and add some examples, pt. 1. by @igalklebanov in #1264
- chore: fix jsdoc errors and add some examples, pt. 2. by @igalklebanov in #1277
- docs: clarify that after rolling back a transaction the exception gets thrown again by @twiddler in #1266
- chore: fix jsdoc errors and add some examples, pt. 3. by @igalklebanov in #1279
π¦ CICD & Tooling
- chore: bump dependencies by @igalklebanov in #1126
- chore: run prettier. by @igalklebanov in #1128
- ci: test against older TypeScript versions. by @igalklebanov in #1192
- chore: add conditional exports test. by @igalklebanov in #1207
- chore: add continuous preview releases. by @igalklebanov in #1219
- Create .renovaterc.json by @igalklebanov in 3f99090
- chore: test deno 2. by @igalklebanov in #1262
- chore: check jsdoc examples. by @igalklebanov in #1263
β οΈ Breaking Changes
π€ New Contributors
- @thelinuxlich made their first contribution in #871
- @dcousineau made their first contribution in #996
- @kansson made their first contribution in #1086
- @Alcas1 made their first contribution in #1092
- @timesince made their first contribution in #1114
- @krijoh92 made their first contribution in #1125
- @tijptjik made their first contribution in #1122
- @cassus made their first contribution in #1139
- @sam-lewis-storyteq made their first contribution in #1156
- @ivashog made their first contribution in #896
- @mxkxf made their first contribution in #1178
- @remiposo made their first contribution in #1216
- @twiddler made their first contribution in #1266
Full Changelog: 0.27.4...0.27.5
0.27.4
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 π
MySQL π¬ / MS SQL Server π₯
- add varbinary data type for mysql by @jonasbovyn in #812
PostgreSQL π
- feat: add 'add column if not exists' for postgres by @MarkusWendorf in #900
- feat: add '?|' comparison operator by @alenap93 in #1006
- feat: add the starts-with postgres comparison operator by @boehs in #1029
- postgres introspection getTables handle partition tables as well. by @HeikoOsigus in #1034
MS SQL Server π₯
- add
OUTPUT
clause support. by @igalklebanov in #828
π Bugfixes
- move
preventAwait
toalter-column-builder
.ts. by @igalklebanov in #1031 - fixes The type of
eb
inselectFrom(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 π₯
- Updating visitMergeQuery to join
WhenNode
s with a space by @gittgott in #940 - fix merge queries not being transformed. by @igalklebanov in #955
- fix
InferResult
not working for merge queries. by @igalklebanov in #902
PostgreSQL π
- Fix typo on timetz regex by @dunkelbraun in #911
MS SQL Server π₯
- fix
MssqlDialect
streaming not handling backpressure. by @igalklebanov in #1041 - fix Tedious v18 includes different TypeScript annotations by @igalklebanov in #1041
- handle connection errors @
MssqlDriver
. by @igalklebanov in #1042
π Documentation
- fix complex join example by @koskimas in 9f836c4
- fix complex join example some more by @koskimas in 8f9038f
- fix complex insert example by @koskimas in ead3489
- improve subquery insert example by @koskimas in 0e194b0
- add not null assertion site example by @koskimas in 58ba4ae
- fix a bunch of untyped sql snippets in API doc examples by @koskimas in 64a56f9
- make it even more clear that table interfaces are not row types by @koskimas in 9485b44
- update outdated intro in kysely.dev by @koskimas in e84863d
- remove snyk badge. by @igalklebanov in 4326a91
- add CTE examples to site by @koskimas in d9a53cd1441e0854456e930eb628f5b03a34db93\
- fix SQLite import @ getting started. by @igalklebanov in #927
- capitalization, more environments @ README. by @igalklebanov in 6ab2155
- fixed docs for deno by @kolay-v in #938
- Added MySQL and MariaDB support information for relation recipes by @chriswep in #800
- Fix spelling, punctuation, grammar by @DePasqualeOrg in #969
- Fix typo (it's --> its) by @davidalber in #1000
- add logging documentation page by @JeromeBu in #1003
- Docs now reflect
tedious
support inBun
by @igalklebanov in #1018 - Docs: Fix typo by @devgru in #1025
- mention
kysely-ctl
in migrations section. by @igalklebanov in #1035 - docs: add comments for
UpdateResult
by @movahhedi in #993 - fix mssql createPerson example. by @igalklebanov in #1048
- docs: fix values example not compiling. by @igalklebanov in #1058
- fix typo incorrect by @zce in #1068
π¦ CICD & Tooling
- migrate to docker compose v2. by @igalklebanov in #932
- ci: bumping actions and runtimes. by @igalklebanov in #942
- ci: drop node16 tests as it reached EOL. by @igalklebanov in 873ed5a
- remove docker-compose file version. by @igalklebanov in #966
- add node22 @ tests. by @igalklebanov in #964
- export all operation nodes, forever. by @igalklebanov in #972
- ci: bump bun, test mssql in bun. by @igalklebanov in #1022
- ci: install only chromium by @igalklebanov in #1043
- bump TypeScript to v5.5. by @igalklebanov in #965
- docs: bump docusaurus to v3. by @igalklebanov in #1050
- docs: remove remaining react imports. by @igalklebanov in #1057
- ci: split jobs. by @igalklebanov in #943
β οΈ Breaking Changes
π€ New Contributors
- @dunkelbraun made their first contribution in #911
- @dswbx made their first contribution in #921
- @kolay-v made their first contribution in #938
- @chriswep made their first contribution in #800
- @jonasbovyn made their first contribution in #812
- @DePasqualeOrg made their first contribution in #969
- @davidalber made their first contribution in #1000
- @JeromeBu made their first contribution in #1003
- @alenap93 made their first contribution in #1006
- @devgru made their first contribution in #1025
- @boehs made their first contribution in #1029
- @HeikoOsigus made their first contribution in #1034
- @movahhedi made their first contribution in #993
- @zce made their first contribution in #1068
Full Changelog: 0.27.3...0.27.4
0.27.3
Hey π
This release happened on 03/09/2024.
What's Changed
- add
cast
method toExpressionBuilder
. 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 inInsertQueryNode
.table
is now optional inUpdateQueryNode
.- 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
- 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
andInsertQueryBuilder#values
methods.
0.27.1
- Add
$notNull
type helper - Support
for update of table
and friends #683 - Support
insert into "person" default values
#685 - Support arbitrary expressions in
limit
andoffset
- 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
- Add mssql dialect. A huge effort by @igalklebanov β€οΈ #595
- Add postgres
json_agg
andto_json
functions to function module - Add
is distinct from
operator #673 - Add
set('first_name', 'Jennifer')
variant for update query'sset
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 tagNotNull
for an easier way to mark columns not nullable manually- Fix #811
- Support arbitrary expressions in
min
andmax
aggregate functions.
Breaking changes
selectNoFrom
is removed fromExpressionBuilder
due to severe typescript performance issues.selectNoFrom
still exists in theKysely
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 forsql
expressions like thissql<string>`something`
- Deprecated functions
eb.cmpr
andeb.bxp
have been removed. Useeb
as a function instead.