Generic type for a specific table query #448
Replies: 1 comment
-
|
In But here is a problem when you want to helperize two queries. The trick that is used underneath is to have 2 types:
Taking the need of 2 types into account, no matter how you specify your generic types - it won't be enough, because the function needs 2 types: one for inside, and one for outside. I can add a new function based on the existing After some thinking, nope, that's not going to work. The current
In the case when you want to pass multiple queries, and return multiple queries, how it would know what arguments to merge with which return types? Can't you use a concrete async function foo() {
const params = await someAsyncOperation()
const users = db.user.where({ active: params.active }).select("id")
const games = db.game.where({ finished: params.finished }).select("id")
return { users, games }
}
const res = await foo()
const [users, games] = await Promise.all([
res.users.select('name'),
res.games.select('createdAt'),
])You can use const res1 = await foo()
const res2 = await bar() // bar is similar to foo
const [users, games] = await Promise.all([
res1.users.merge(res2.users).select('name'),
res1.games.merge(res2.games).select('createdAt'),
]) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I would like to create functions that accept a query against certain table (thus allowing field-level type-checks), and allow the return type of the function to be properly inferred. Example:
Is something like this possible, perhaps for some simpler/limited scenarios (no aliases/relations/joins involved)?
Beta Was this translation helpful? Give feedback.
All reactions