I was wondering about a feature in Ktor/Exposed 🙂
Assume i got a table
Copy code
ID | User | value
1 | 1 | value1
2 | 1 | value2
3 | 2 | value3
In other ORM frameworks, if I want to extract only values from user=1, I could create a DB session and use
Values.all()
and it'll fetch only [value1, value2]
I don't want to fetch via
Values.select { Values.user eq user }
🤦♂️ 1
b
Bogdan
10/15/2021, 3:32 PM
I wonder how the framework should understand that you only need to filter by user = 1?
j
John Pali
10/15/2021, 3:33 PM
DB sessions?
b
Bogdan
10/15/2021, 3:34 PM
the session does not say anything about the limitations of data fetching, give an example of an ORM where it is possible
👍 1
j
John Pali
10/15/2021, 8:31 PM
@Bogdan so how would you address something like that?
query all models with
modelX.user eq user
?
b
Bogdan
10/16/2021, 8:49 AM
if all values of all users are used then
Values.all ()
is used. If you need to unload all values for a specific user, then use
Values.user eq userId
Bogdan
10/16/2021, 8:50 AM
PS: this is DSL syntax, to use ORM you need to look at DAO section
d
dave08
10/16/2021, 9:12 PM
You could always make some kind of variable saving the user id (maybe saved in the thread), and implement your own all() that uses that variable to limit the request... But I personally don't like global vars...