Releases: kysely-org/kysely
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.
0.26.3
0.26.2
- Added support for select statements without a
from
clause. The function is called selectNoFrom. The function name was selected after a lot of discussion. The most natural name would just beselect
, but new users would find that in a list of autocompletions beforeselectFrom
and naturally use it when trying to create aselect from
query. This would be especially true for people coming from knex where aselect from
query is started using aselect
call. #605 - Add object variants of
and
andor
functions. Allows easywhere(eb => eb.and(object))
filters. #583 - Add support for tuples. See some examples here. #611
- Add addPrimaryKeyConstraint for AlterTableBuilder. #639 Thank you @n7olkachev β€οΈ
- Add
any
function to function module. #612 - Add
between
method to expression builder. #602 - Add
lit
method to expression builder. #600 - Add multi-column variant of
orderBy
. #423 Thank you @igalklebanov β€οΈ
An example of an object and
call:
const persons = await db
.selectFrom('person')
.selectAll()
.where((eb) => eb.and({
first_name: 'Jennifer',
last_name: eb.ref('first_name')
}))
.execute()
select * from "person"
where "first_name" = $1 and "last_name" = "first_name"
0.26.0
Expression builder improvements
We improved the expression builder based on excellent feedback from the community in this issue in addition to many discord discussions. Unfortunately this means deprecating the recently added cmpr
and bxp
methods, but the migration should be painless. Read more @ #565.
Before you could create comparisons and arbitrary binary expressions using cmpr
and bxp
respectively:
where((eb) => eb.or([
eb.cmpr('first_name', '=', 'Jennifer'),
eb.cmpr('first_name', '=', 'Sylvester'),
]))
set((eb) => ({
age: eb.bxp('age', '+', 1)
}))
After this release, you'd do this instead:
where((eb) => eb.or([
eb('first_name', '=', 'Jennifer'),
eb('first_name', '=', 'Sylvester'),
]))
set((eb) => ({
age: eb('age', '+', 1)
}))
As you can see we made the expression builder callable and it can create all kinds of binary expressions. You can still use destructuring as before since the expression builder has a new property eb
that returns itself:
where(({ eb, or }) => or([
eb('first_name', '=', 'Jennifer'),
eb('first_name', '=', 'Sylvester'),
]))
or
and and
chaining
We've also added new way to create and
and or
expressions using chaining
where((eb) =>
eb('first_name', '=', 'Jennifer').or('first_name', '=', 'Sylvester')
]))
The old and
and or
methods are still there and are not going anywhere.
JSON references
The expression builder's ref
function can now be used to reference nested JSON columns' fields and array items in a type-safe way:
// Postgres syntax: "addresses"->0->'postalCode'
where(({ eb, ref }) =>
eb(ref('addresses', '->').at(0).key('postalCode'), '=', '61710')
)
// MySQL syntax: `addresses`->'$[0].postalCode'
where(({ eb, ref }) =>
eb(ref('addresses', '->$').at(0).key('postalCode'), '=', '61710')
)
The JSON reference builder is just our first guess of a good API. We're eager to hear your feedback. More examples and a recipe on the subject will follow shortly after this release. Read more @ #440.
Other changes
- fix onConflict compilation errors starting from TypeScript 5.1.6 #568. Thanks @igalklebanov β€οΈ
- Add UpdateResult.numChangedRows. #431 Thanks @wirekang β€οΈ
- Disallow AlterColumn method chaining. #468 Thanks @soanvig β€οΈ
- Allow arbitrary expressions in count and sum
- Allow parameters in raw sql. #512 Thanks @nicksrandall β€οΈ
0.25.0
Large amount of contributions from many awesome people in this one, but one definitely stands out:
Using his sorcerous knowledge of the typescript compiler internals @schusovskoy was able to significantly reduce the possibility of the notorious Type instantiation is excessively deep and possibly infinite
compiler error throughout Kysely. Check out the PR here #483 π§. In our typing tests, we were able to at least double the complexity of the troublesome queries without hitting slowdowns or compiler errors. In some cases the issue seems to have gone away completely.
Simply amazing work. Thank you so much @schusovskoy β€οΈ
Other fixes and improvements in no particular order:
- Add new
case when then end
builder #404. Thanks @igalklebanov β€οΈ - Allow specifying column sort order when creating indexes #375. Thanks @igalklebanov β€οΈ
- Add
$narrowType
helper for narrowing the query output type #380. Thanks @igalklebanov β€οΈ - Make subquery selections nullable by default #420
- Fix alter table schema handling #471. Thanks @hannesj β€οΈ
- Add
agg
method to expression builder for arbitrary aggregate function calls #417 @igalklebanov β€οΈ - The
$if
method should no longer cause performance issues or excessively deep types - Make logger support async calls #425. Thanks @mehulmpt β€οΈ
In addition to this there were small fixes from multiple awesome people including:
- #499 #463 by @neographer
- #444 by @rafaumlemos
- #478 by @thdxr
- Work on kysely.dev by @wirekang and @naorpeled
0.24.2
- Add mysql helper module with
jsonArrayFrom
andjsonObjectFrom
functions. See this recipe for more info.
0.24.0
So much new stuff and big improvements, I don't know where to start! π. There should be no breaking changes, but with this amount of changes and new features, it's always possible we've broken something π¬. As always, please open an issue if something is broken.
Let's start with the reason some of you are here: the deprecated filter methods and the improved ExpressionBuilder
:
The improved ExpressionBuilder
We've deprecated most of the where
, having
, on
and other filter methods like whereExists
, whereNotExists
, orWhere
, orWhereExists
in favour of the new expression builder. To get an idea what the expression builder is and what it can do, you should take a look at this recipe. Here are some of the most common migrations you should do:
// Old
where(eb => eb
.where('first_name', '=', 'Jennifer')
.orWhere('last_name', '=', 'Aniston')
)
// New
where(({ or, cmpr }) => or([
cmpr('first_name', '=', 'Jennifer'),
cmpr('last_name', '=', 'Aniston')
]))
// Old
whereNotExists(eb => eb
.selectFrom('pet')
.select('pet.id')
.whereRef('pet.owner_id', '=', 'person.id')
)
// New
where(({ not, exists, selectFrom }) => not(exists(
selectFrom('pet')
.select('pet.id')
.whereRef('pet.owner_id', '=', 'person.id')
)))
You can fine more examples here and here.
The new website π
The first version of kysely.dev is out π A huge thanks to @fhur for the initiative and for doing allmost all work on that β€οΈ
Now that the site is out, we'll concentrate on adding more documentation and examples there. For now, it's pretty minimal.
Other changes
- Add compiled query and timings to error logs. Thank you @fwojciec β€οΈ #355
- Add
returningAll('table')
overload forDeleteQueryBuilder
. Thank you @anirudh1713 β€οΈ #314 - Fix #398. Thank you @igalklebanov β€οΈ #399
- Allow streaming of
update
,insert
anddelete
query results on postgres. Thank you @igalklebanov β€οΈ #377 - Add
where
method toCreateIndexBuilder
. Thank you @igalklebanov β€οΈ #371 - Added a new module
kysely/helpers/postgres
for some postgres-spcific higher level helpers. Similar packages will be added for other dialects too in the future. See this recipe for the newly available helpers. - Simplified types (performance-wise). Small gains here and there.