Select by id?
Why has the json_agg and to_json call functions not been released?
Why jsonArrayFrom converts a Generated<number> field into string | number?
kysely uses prepared statements like knex?
How to improve performance in large SELECT?
$assertType()
with a hard-coded object type at the end of the select query, but it doesn't help much.
Is there a recommended way for large inferred types?...Type inference of queries with expressions in Webstorm
const result = await selectable.select(({ eb }) => eb(eb.fn.count('id'), '>', 0).as('email_exists')).executeTakeFirst()
is {email_exists: SqlBool} | undefined
...How to compose functions?
select count(id) > 0 from foo
. I tried this:
.select(({ eb }) => {
eb(eb.fn.count('id'), '>', 0)
})
....select(({ eb }) => eb(eb.fn.count('id'), '>', 0).as('email_exists'))
I learned this by accidentally stumbling across this note in the documentation:
You can select arbitrary expression including subqueries and raw sql snippets. When you do that, you need to give a name for the selections using the as method....
How do I create a helper to be used on a select array of fields?
How do I cast the type of a eb.fn('...') ?
eb.fn('now', []).$castTo<Date>()
eb.fn('now', []).$castTo<Date>()
cant use kysely-codegen
npm install --save-dev kysely-codegen
, and I set database string in .env
file. Next step is: kysely-codegen
, but I get this error when I type it in the console:
```
kysely-codegen
kysely-codegen : The term 'kysely-codegen' is not recognized as the name of a cmdlet, function, script file, o ...npx kysely-codegen
workswithSchema is marked as deprecated in ExpressionBuilder?
Insert values from subquery
eb.lit
:
To prevent SQL injections, only boolean, number and null values are accepted. If you need string or other literals, use sql.lit instead.
To prevent SQL injections, only boolean, number and null values are accepted. If you need string or other literals, use sql.lit instead.
$if with sql.raw doesn't compile
const filterWhereQuery = sql.raw(
LOWER("${dimensionName}") LIKE '%${filter?.toLowerCase()}%');
...<SqlBool>
generic to your sql
template tag....ORDER BY in agg function.
json_agg(table ORDER BY column) as values
json_agg(table ORDER BY column) as values
Binary fields in mySQL
typeCast
config of mysql2
```ts
typeCast: function (field, next) {
if (field.type === 'TINY' && field.length === 1) {...jsonb_build_object and raw sql possibilities
``
sql<string>
jsonb_build_object(${sql.join([
sql.raw('hair_type',coalesce (dog.hair_type, dog_breed.hair_type)
),
sql.raw('ear_type',coalesce (dog.ear_type, dog_breed.ear_type)
),...ts_rank in select
as
method.
sql<number>`ts_rank(to_tsvector('english', users.email, websearch_to_tsquery('R2023-185'))`.as('rank'),
sql<number>`ts_rank(to_tsvector('english', users.email, websearch_to_tsquery('R2023-185'))`.as('rank'),
How to convert this raw query to kysely?
Converting a more complex query to Kysely
Error "isSelectQueryBuilder" while using doUpdateSet on conflict
doUpdateSet
expression during an on conflict statement for an insert.
From my experiments, if the select type of the column is different (not assignable to) the insert/update types than something breaks at the type level and gives me an error
Repro:
https://kyse.link/?p=s&i=Wt7lre2AUUH7EdAInOja...