What is the type for an .orderBy() parameter
Inside of a function, i have a query more complicated than this, but something like:
I'd like to be able to pass in the
part of that from the outside., but to do that I need to know what type i should be putting on the function parameter.
5 Replies
You can take a look at the function definition in the .d.ts file for cases like this:
What this means is it accepts two sets of arguments:
- a callback that returns a single value or an array of either AnyPgColumn, SQL or SQL.Aliased
- spreaded arguments of either AnyPgColumn or SQL
SQL instances are created with
sql
tag calls (which all the operator functions, like asc
, do under the hood), SQL.Aliased is sql`query`.as('alias')
You can just go with the second set of arguments if it satisfies your needs.
Also, a good way to figure out an expression type is to assign it to a variable and looking at its type.i did try that, before posting here, but it doesn't work
TSelection is something you are creating outside orderBy
same with ...columns
so just trying to make something partial like this:
results with this:
on the orderBy parameter
That's because that's a spread argument. You need to pass it like this:
.orderBy(...orderBy)
i see, i'm dumb
š
thank you
how can I order row as random??
no need this I got solution,