Using sql.lit
Any thoughts on how to move data migrations from knex to kysely?
Using a custom HTTP driver for Kysely
kysely-planetscale
), or do I need to make the driver myself?How to order by with embeddings using pgvector?
Recipe for generated types + JSON?
Consensus on immutable vs. mutable result for .executeTakeFirst
executeTakeFirst
should be immutable? Or is this up to the dialect/not a concern of Kysely?
I'm asking because I seem to have found an inconsistency with kysely-libsql where the result of executeTakeFirst
is immutable, but this isn't the case for built-in dialects (checked Sqlite and Pg). ...CamelCasePlugin
, Kysely doesn't touch the result in any way. It just returns what the driver returns.Relational table join question
user
and account
joined via the user_account
relational tables, if I use jsonArrayFrom
from a query on the user
table to get accounts, do I always need to do a join with the intermediary table or does Kysely provide any type of shortcut for this?Raw SQL in select type to number
sql<number>`(${sql.raw(precisionScore)} * 100)::NUMERIC(10,2)`
sql<number>`(${sql.raw(precisionScore)} * 100)::NUMERIC(10,2)`
pg
driver returns numeric type as a string. Use the pg-types
package to configure the type.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.