djMax
Multiple calls to values in insert statement?
I just had a production bug where I was calling
.values
multiple times on a query object. I've fixed it by passing an array to a single values call instead, but this seems like a bug no? Either the types should reflect that values can no longer be called after it has been, or it should collect the values calls into one array?7 replies
How can I get total row count without blowing up types?
I have a simple query function that is in charge of generating a list of ids so that it can be passed into a function which does some other fancy stuff with those ids as a CTE. Like so:
Now, the problem is I also want to get the total row count with
COUNT(*) OVER()
so that I don't have to make two trips. But if I try to add sql
to the select list to get that value, the type system loses its mind... Can I somehow cast the sqlCOUNT(*) OVER()
to behave as if the query is going to return a column with the name total and make it not worry about how?4 replies
Generic function to stream a table
I am trying to write a generic function that will take a kysely connection, a table name, a column name and a value for that column and return a streaming select. I can't figure out the "foward type declarations" to make it all work, and I think it's because of some of the fancy bits that Kysely does for selectFrom("table as alias") that I can't untangle. Playground link here: https://kyse.link/?p=s&i=n4OdlKPOjCkNULp6niLU . As you can see, it does WORK, but the red squigglies mean TS thinks it's wrong. Any idea how to declare this properly? Thanks!
5 replies
How do you formulate a custom type argument?
I would like to pass a record type to a postgres function with kysely. How do I do that? I get "malformed record literal" when I try the obvious things. I'm sure I can raw-sql it together but I'd like to do it as properly as possible.
4 replies
How do I type the arguments to a function?
I am calling a stored proc with parameters (we have very few, but some make the client's life a lot easier and make transactions shorter). I get an error that it can't find the function given the types:
I'm calling it like:
Do I need to just cast each one in the SQL?
3 replies