K
Kysely5mo ago
mike

How to like left value to right raw statement?

Unsuccessful attempts: https://old.kyse.link/?p=s&i=RXSid8MMyDZRXfcl8Jdq Expected result:
SELECT *
FROM geography.postal_areas
WHERE $1 LIKE "postalCode" || '%';
SELECT *
FROM geography.postal_areas
WHERE $1 LIKE "postalCode" || '%';
13 Replies
Igal
Igal5mo ago
Hey 👋 Here's a way of doing this:
.where((eb) =>
eb(
eb.val("Paulee"),
"like",
eb("first_name", "||", sql.lit("%")),
),
)
.where((eb) =>
eb(
eb.val("Paulee"),
"like",
eb("first_name", "||", sql.lit("%")),
),
)
https://kyse.link/4Tq7n
mike
mike5mo ago
great! thank you very much
mike
mike5mo ago
@Igal any idea why I get this?
No description
Igal
Igal5mo ago
What kysely version are you on?
mike
mike5mo ago
❯ npm -v kysely >>> 8.19.2
Igal
Igal5mo ago
that's npm version. try npm explain kysely
mike
mike5mo ago
❯ npm explain kysely [email protected] node_modules/kysely kysely@"^0.25.0" from the root project
Igal
Igal5mo ago
kysely's latest version is 0.27.3 For 0.25.0:
.where((eb) =>
eb.cmpr(
eb.val("Paulee"),
"like",
eb.bxp("first_name", "||", sql.lit("%")),
),
)
.where((eb) =>
eb.cmpr(
eb.val("Paulee"),
"like",
eb.bxp("first_name", "||", sql.lit("%")),
),
)
https://kyse.link/GKkwI
mike
mike5mo ago
I installated the latest one and it works! thanks a lot @Igal however after upgrade to the latest version I get following error. I checked the release history and fixed multiple deprecated things but this one is hard to identify...
.where((eb) =>
eb.or([ // // Type 'RawBuilder<unknown>' is not assignable to type 'OperandExpression<SqlBool>'. Property 'isSelectQueryBuilder' is missing in type 'RawBuilder<unknown>' but required in type 'SelectQueryBuilderExpression<Record<string, SqlBool>>'.
sql`row-sql`, // when removing this line it's ok
eb('column1', 'is', null),
])
)
.where((eb) =>
eb.or([ // // Type 'RawBuilder<unknown>' is not assignable to type 'OperandExpression<SqlBool>'. Property 'isSelectQueryBuilder' is missing in type 'RawBuilder<unknown>' but required in type 'SelectQueryBuilderExpression<Record<string, SqlBool>>'.
sql`row-sql`, // when removing this line it's ok
eb('column1', 'is', null),
])
)
Igal
Igal5mo ago
sql<SqlBool>`row-sql`,
sql<SqlBool>`row-sql`,
mike
mike5mo ago
yeah, it fixed the issue. can you provide a link to a source explaining the SqlBool type and why/how to use it? I don't want to bother with stupid questions. I prefer to read docs and understand it.
koskimas
koskimas5mo ago
You don't need to use SqlBool. boolean is is just fine or 0|1 if you're on a dialect that doesn't have booleans. SqlBool is just boolean | 1 | 0 which is the union of each dialects' boolean types. If you know your dialect (as you always should with Kysely) you can use its boolean type
mike
mike5mo ago
I am on psql dialect btw
Want results from more Discord servers?
Add your server