6 ms·
How is this DSL acceptable? posts = await client.post.find_many( where={ 'OR': [ {'title': {'contains': 'prisma'}},
by inshadows 5y ago
How is this DSL acceptable?
posts = await client.post.find_many(
where={
'OR': [
{'title': {'contains': 'prisma'}},
{'content': {'contains': 'prisma'}},
]
}
)
SQL for comparison:
... where title like '%prisma%' or content like '%prisma%'
- lucas_codes 5y agoNow try filtering on a relation!
- probablyrobert 5y agoI find the relational API very easy and intuitive to work with. What do you not like about it?
- lucas_codes 5y agoSo do I - the parent is choosing to compare the most basic example which didn't show the benefits of using an orm over raw sql
- probablyrobert 5y agoAh sorry I misread your comment, I thought you were agreeing and saying that filtering by a relational field is also unacceptable DSL. Thank you :)
- subsection1h 5y agoThis is one of the things I've never understood about ORMs. They're not helpful for simple queries, but they're also not helpful for the most complex queries. When I've used ORMs in past (e.g., Active Record), we regularly needed to bypass the ORM to write raw SQL for complex queries in order to get the best performance.
- mypalmike 5y agoWith Python and SqlAlchemy, I was surprised how intuitive some rather complex queries were to write and read, and by the quality of the generated SQL.
- probablyrobert 5y agoHow do you suggest to improve it?
- inshadows 5y agoWrite SQL.
- jjice 5y agoI think the parent is saying that the SQL example is simpler and easier to read.
- vonseel 5y agoYeah, but he’s completely skipping over the fact that you’re going to lose some of the readability of short SQL statements switching to an ORM with methods, types/classes, functions, etc., but you can gain in maintainability of code.
- IanCal 5y agoNot the original author, but "or" at the start then a list may be better called "any". That (to me) would read more clearly. Particularly if you were passing in the contents, '"or": var' would make me think "var or what?" But '"any": var' seems more obvious. Has a clear link to the python "any" as well
- probablyrobert 5y agoThanks for the suggestion, I've created an issue to track this as I do agree that `ANY` conveys the operation more clearly. https://github.com/RobertCraigie/prisma-client-py/issues/293 https://github.com/RobertCraigie/prisma-client-py/issues/293
- dgb23 5y agoHaven’t used prisma but I think their query builder type checks (not just the results) which make composing and writing them quite a bit more convenient than the example shows.
- mypalmike 5y agoTry making an apples to apples comparison. You neglected to write the SELECT, which would typically not be as simple as "SELECT * from post". You neglected to write the code to iterate over the results, which is trivial in the ORM version. In the SQL version it requires cursors and the error-prone manual mapping of positional data to named data.
- inshadows 5y agoBullshit. I don't need to use cursor with Python's sqlite3 module if I use the shorthand API exported by the module. I can write abstractions in Python. But I don't need to write shitty abstractions like the one for filtering.