Skip to content

0.26.0

Compare
Choose a tag to compare
@koskimas koskimas released this 07 Jul 17:00
· 206 commits to master since this release

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 ❤️