Raw query for RLS not working
I am trying to migrate a raw query from TypeORM's builtin query builder to Kysely.
It's required to be raw as Kysely unfortunately does not fully implement Postgres's SQL language.
Original query:
``
const query =
...Problems typing a generic withPerson helper
First I want to say that I'm in love with Kysely! It's amazing. I could use some help getting the types right for a helper function I'm creating.
I'm trying to follow the relations recipe (the withPets and withMom example from the docs), but I want to make it slightly more reusable.
I have a withPerson method...
Rollback transaction
Hi, I'm trying to figure out if it's possible to intentionally rollback a transaction, the idea is that if one insert into the database ends with certain return value, the whole transaction should end and the insert rolled back. Knex has
trx.rollback
on the callback parameter, but I couldn't find anything like that on Kysely, am I missing something or is this not yet implemented?Solution:
Okay I was doing raw sql badly, this does work at least...
await sql<void>`rollback`.execute(trx)
await sql<void>`rollback`.execute(trx)
Trouble running migrations
I am trying to use Kysely on a svelte-kit project, I set up the migration script like the example shown in the docs, but when trying to run the script with I tried changin the migration file name, making it a JS file instead of TS but still get the same error, I am not sure what I am doing wrong, the scripts are the same as the examples in the docs....
ts-node --esm "path/to/script"
I receive failed to migrate
CustomError: ERR_INVALID_MODULE_SPECIFIER src\lib\server\db\migrations\540540540_create_db.ts is not a valid package name E:\Code\Web\portfolio-projects\spotify-cp\node_modules\.pnpm\[email protected]\node_modules\kysely\dist\esm\migration\file-migration-provider.js
CustomError: ERR_INVALID_MODULE_SPECIFIER src\lib\server\db\migrations\540540540_create_db.ts is not a valid package name E:\Code\Web\portfolio-projects\spotify-cp\node_modules\.pnpm\[email protected]\node_modules\kysely\dist\esm\migration\file-migration-provider.js
Suggestions on implementing SQLite as DocumentDB or GraphDN
Would love recommendations on using Kysely to implement something similar to the following.
https://github.com/dpapathanasiou/simple-graph
https://dgl.cx/2020/06/sqlite-json-support
Video in case it's helpful - https://www.hytradboi.com/2022/simple-graph-sqlite-as-probably-the-only-graph-database-youll-ever-need
It seems like a perhaps using sql.raw helpers and abstracting in plugins, then perhaps some TS magic to make the QueryBuilder and other types to work....
open source examples
Do you know of a mid-large size open source codebase that has integrated kysely?
Size isn’t most important here, but I’m curious to see edge cases and sophisticated use cases may arise in a sufficiently complex system....
Types for use with leftJoin
Hiya! I'm attempting to do a leftJoin and return the result:
```
const result = await db
.selectFrom("accounts")...
mysql InsertResult always empty
my app is heavy id/transaction user and i need the id of created register to insert another register but InsertResult always is empty
RawBuilder is not "Compilable"
How one should execute RawBuilders coming from (for example)
sql
```
since they're not "Compilable" things? I know you can pass from
```
since they're not "Compilable" things? I know you can pass from
customsql
.execute({ getExecutor: () => executor })...Query with ANDs and ORs - struggling with syntax
I want to be able to create a query that looks like this - i.e. has a first WHERE section
that must be true then an either/or but struggling to get the syntax right
SELECT * FROM user
WHERE ...
Subquery type error when using generics
I have the following simple query being generated by my function
f
:
``typescript
const f = () => queryBuilder
.deleteFrom(
table as t1)
.whereExists(qb => qb.selectFrom(
table as t2`)...Extacting where clause generation into dedicated function
I'm building up a query dynamically and need to use some of the logic embedded in where clauses from multiple functions. Therefore, I'd like to encapulate this in a separate function that can be reused but I'm struggling with the type signatures for that function.
An example of a query that I'd like to encapsulate is:
```ts
query = query.where((qb) => {...
createQueryId
Is this function supposed to be exported and used in users code? I'm handling query execution with a custom executor and the
executeQuery
method asks me for a QueryId
. Am I supposed to use kysely internal implementation or am I free to use a custom one? It's just a random string I see, but does it involve something else internally?
I'm asking cause the default import is set to: import { createQueryId } from "kysely/dist/cjs/util/query-id"
...Insert expression type safe
Is there a way to make
.expression
calls while inserting to a table to return an "InsertObject" or an array of column name / value as when using .values
method so to have type safety in the query?
Example right now:
```typescript
type Table = { a: string, b: number }...Property "values" missing when Inspecting InsertQuery ValuesNode
I'm having some troubles upgrading from 0.22.0 to 0.23.4, because I have a custom plugin which gets some columns as input for each database table and prevent any other column to be used as the target of an InsertQuery (this way I can silently pass
{ id: 42, username: "John", nonExistingColumn: "error at runtime" }
as an insert value for my user
table without worrying about excessive properties in the values.
I have overriden the:
```typescript
protected override transformInsertQuery(_node: InsertQueryNode): InsertQueryNode...How to make a top level SELECT that isn't from a table?
I'm trying to combine two queries,
SELECT COUNT(*) FROM A
and SELECT COUNT(*) FROM B
.
SELECT (SELECT COUNT(*) FROM A), (SELECT COUNT(*) FROM B)
does what I want. How can I convert this to Kysely?
My real code also returns two scalars, so I could theoretically use a UNION ALL
- however I'm not sure if the return order is guaranteed in MySQL. I'm open to other solutions that don't have a top level SELECT....