K
Kysely6mo 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
Igal6mo 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
mikeOP6mo ago
great! thank you very much
mike
mikeOP6mo ago
@Igal any idea why I get this?
No description
Igal
Igal6mo ago
What kysely version are you on?
mike
mikeOP6mo ago
❯ npm -v kysely >>> 8.19.2
Igal
Igal6mo ago
that's npm version. try npm explain kysely
mike
mikeOP6mo ago
❯ npm explain kysely [email protected] node_modules/kysely kysely@"^0.25.0" from the root project
Igal
Igal6mo 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
mikeOP6mo 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
Igal6mo ago
sql<SqlBool>`row-sql`,
sql<SqlBool>`row-sql`,
mike
mikeOP6mo 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
koskimas6mo 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
mikeOP6mo ago
I am on psql dialect btw
Want results from more Discord servers?
Add your server