Execute RAW Sql Queries
kysely
? i could not find any such function in the docs or the guide book
for example, describe table_name
errors because kysely itself cannot compile it. i am using mysql2
as my driver....await sql`RAW QUERY HERE;`.execute(db);
await sql`RAW QUERY HERE;`.execute(db);
Selecting result of subtraction with summation
"inventory.initial_quantity"
, rather than wrapping it in eb.val
š¤¦āāļøMigrator transaction (postgresql dialect)
BEGIN
before and COMMIT
at the end?
```...migrateToLatest()
all migrations are run in a single transaction. They either all succeed or none of them succeed.
Also when you run migrateTo
the same happens. The only case where you get individual transactions is when you run the migrations in multiple calls.
You can't use migrateTo
or migrateToLatest()
?...Kysely client usage and pooling question
Implementing D1 batching (getting typed queries as input and returning typed InferResult)
executeBatch
method and I want to infer the results for each of the individual queries. Is this possible?Iām well versed in SQL and priority #1 is performance. Can Kysely still make sense for me?
Creating helper functions
how to union two queries with json_build_object?
QueryA | QueryB
. this query fails the type checker but the generated query seems to work as intended. is there a type hint i can provide somehow?
https://kyse.link/2TBLF...first_name
in the first one an name
in the second one. If both have the same property name it works. https://kyse.link/Bc300
When you use different keys, the correct type of the JSON object would be { name: string |Ā undefined, first_name: stringĀ | undefined }
but Kysely isn't able to infer it....bulk-insert with constant variable as one column
Making CTE's reusable
pg migration raw sql CREATE FUNCTION gets error: "TypeError: Cannot redefine property: then"
``
await sql
CREATE FUNCTION universal_history_trigger_function()...You have two (or more) incompatible versions of Kysely and you are mixing parts of them.In my case this somehow occurred from kysely v0.27.3 + kysely-ctl 0.8.7. Bumped to v.0.27.4 + 0.9.0 respectively fixed it....
Roll back transaction prematurely
Error
inside the execution callback method?
```ts
return this._db.transaction().execute(async trx => {
const entryType = await this._db...``ts
/**
* Wraps a Kysely transaction such that any
Err` returned from the callback results in a rollback....Dynamic query parts based on user input
Unable to use table name with 3 dots in selectFrom
Updateable primary key question & .set() type safety
ColumnType
with never
in the 3rd generic value.
```ts...Error: don't await SelectQueryBuilder instances directly.
execute
or executeTakeFirst
.
I'm trying to create a function that enhances the query (SelectQueryBuilder
) with pagination, sorting and filtering options that are derived from a HTTP request.
This function looks like:...then
method gets called. Kysely query builders all have a then
method that throws that exception. It's there because many other query builders and ORMs allow you to do stuff like
const result = await db.selectFrom('person').selectAll()
const result = await db.selectFrom('person').selectAll()
JSON Object Traversal
sess
column:
```json
{
"cookie": {...->>
for all of them?express-session store
express-session
. For example, to use in combination with passport
.
For example, I was wondering if Kysely somehow exposes a pg
compatible pg.Pool
, which would allow me to use something like connect-pg-simple
to have an adapter from the Kysely world to the pg
world....pg.Pool
that Kysely uses when I added the Postgres dialect, so that solves that problem šSynchronous queries to SQLite?
better-sqlite3
is a synchronous library and Kysely's SQLite dialect uses better-sqlite3
, so is there a way to make synchronous queries?