Converting CASL conditions to MikroORM query conditions - need guidance on best practices #1048
Unanswered
only-issues
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi CASL team and community! 👋
I'm working on integrating CASL with MikroORM and while I've seen discussion #949 about Collections handling, my main challenge is with converting CASL's MongoDB-style conditions into MikroORM query conditions.
The core problem
CASL generates conditions using MongoDB query syntax (which is great!), but when I need to apply these conditions to actual database queries through MikroORM, I'm struggling with the translation layer.
Example scenario:
What I've tried
Manual operator mapping: Started creating a mapping function for each MongoDB operator (
$in
,$ne
,$or
, etc.) but it's getting complex quickly and I'm worried about edge cases.Looking into @ucast/sql: I saw mentions of this in issue Request for TypeORM #347 for TypeORM, but I can't find clear documentation on how to use it with MikroORM specifically.
Serialization approach: Converting everything to JSON first, but this defeats the purpose of having database-level filtering.
Specific challenges I'm facing
author.profile.country
$and
,$or
,$not
combinations$in
,$nin
,$elemMatch
to work with MikroORM's syntaxWhat I'm looking for
Recommended approach: Is there a standard/recommended way to bridge CASL conditions with SQL-based ORMs like MikroORM?
Existing solutions: Has anyone built or knows of a helper library for this specific translation?
@ucast/sql guidance: If @ucast/sql is the way to go, could someone provide guidance on integrating it specifically with MikroORM?
Best practices: What's the most maintainable approach for handling this conversion layer?
Code example of what I need
Ideally, I'm looking for something like:
Context
I really appreciate CASL's approach to authorization and would love to make this work smoothly with MikroORM. Any guidance, code examples, or pointers to existing solutions would be incredibly helpful!
Thanks for your time and for building such a great library! 🙏
Note: This is separate from the Collections issue discussed in #949 - I'm specifically focused on the conditions mapping challenge.
Beta Was this translation helpful? Give feedback.
All reactions