kysely-org / kysely

A type-safe typescript SQL query builder
https://kysely.dev
MIT License
9.82k stars 250 forks source link

where with sql complains about Property 'isSelectQueryBuilder' is missing #982

Closed unilynx closed 2 months ago

unilynx commented 2 months ago

I'm running into problems with where & sql in v0.27.2 when using: .where('id', '=', sql`any(${['1', '2', '3']})`) - a syntax that worked with v0.23.5:

"Argument of type 'RawBuilder' is not assignable to parameter of type 'ExpressionOrFactory<DB, "person", SqlBool>'. Property 'isSelectQueryBuilder' is missing in type 'RawBuilder' but required in type 'SelectQueryBuilderExpression<Record<string, SqlBool>>'.(2345)

I've taking this example https://kysely-org.github.io/kysely-apidoc/interfaces/Sql.html and as far as I can tell it will now generate the same error: https://old.kyse.link/?p=s&i=IRUTxKuKdZwxKHs8snN8

Is this a Kysely issue or is the example outdated ?

igalklebanov commented 2 months ago

Hey 👋

This is a documented breaking change in https://github.com/kysely-org/kysely/releases/tag/0.27.0.

In your case, you should add a generic with the type of the "id" column to sql template tag.

You should add <SqlBool> in the examples you linked:

import { SqlBool } from 'Kysely'

// ...

.where(sql<SqlBool>`birthdate between ${date1} and ${date2}`)

https://old.kyse.link/?p=s&i=m1mbEmpAtm7Gpgyvf1EE

Also note, we have built-in support for between now in ExpressionBuilder:

.where((eb) => eb.between('birthdate', date1, date2))

https://old.kyse.link/?p=s&i=rigM1aWB3lgbPBQeXQ23

We should update the examples you saw.