Joe
Joe
KKysely
Created by Joe on 1/27/2024 in #help
Raw SQL in where clause
I have the following code and I'm getting a type error. This is strange as the raw sql statement works for insert statements but doesn't seem to play nice with the where clause. In addition, the code below seems to work before 0.27.0.
await this.database
.get()
.selectFrom('fiat_country')
.where('disabled_at', '>', sql`now()`)
.selectAll()
.execute();
await this.database
.get()
.selectFrom('fiat_country')
.where('disabled_at', '>', sql`now()`)
.selectAll()
.execute();
error TS2345: Argument of type 'RawBuilder<unknown>' is not assignable to parameter of type 'OperandValueExpressionOrList<DB, "fiat_country", "disabled_at">'.
Property 'isSelectQueryBuilder' is missing in type 'RawBuilder<unknown>' but required in type 'SelectQueryBuilderExpression<Record<string, Date | null>>'.

78 .where('disabled_at', '>', sql`now()`)
~~~~~~~~~~
error TS2345: Argument of type 'RawBuilder<unknown>' is not assignable to parameter of type 'OperandValueExpressionOrList<DB, "fiat_country", "disabled_at">'.
Property 'isSelectQueryBuilder' is missing in type 'RawBuilder<unknown>' but required in type 'SelectQueryBuilderExpression<Record<string, Date | null>>'.

78 .where('disabled_at', '>', sql`now()`)
~~~~~~~~~~
With that said, if I cast the sql statement to never it seems to resolve the problem. But I don't think that's the proper fix.
await this.database
.get()
.selectFrom('fiat_country')
.where('disabled_at', '>', sql`now()` as never)
.selectAll()
.execute();
await this.database
.get()
.selectFrom('fiat_country')
.where('disabled_at', '>', sql`now()` as never)
.selectAll()
.execute();
Here's what I'm using: kysely: 0.27.2 kysely-codegen: 0.12.0 Appreciate it if anyone have any insides to this! 🙏🏻
4 replies
KKysely
Created by Joe on 7/21/2023 in #help
NOW() function in kysely
For instance, this statement is valid on Postgres: INSERT INTO films VALUES ('UA502', 'Bananas', 105, NOW()); I was wondering if there was anyways to achieve the same thing in kysely. Thank you 😄
12 replies