-
Notifications
You must be signed in to change notification settings - Fork 170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Crude implementation to allow map values to be part of the check cond… #130
Crude implementation to allow map values to be part of the check cond… #130
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some comments. I think it could be written a bit more clearly for understanding's sake but I can see the general idea behind it and think this would fix at least one open issue in GH.
: error(`A string for 'attr' or 'size' is required for condition expressions`) | ||
// Add filter attribute to names | ||
let attrName = ""; | ||
const path = typeof attr === 'string' ? attr.split('.') : typeof size === 'string' ? size.split('.') : error(`A string for 'attr' or 'size' is required for condition expressions`);; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Double semi colon at EOL.
let attrName = ""; | ||
const path = typeof attr === 'string' ? attr.split('.') : typeof size === 'string' ? size.split('.') : error(`A string for 'attr' or 'size' is required for condition expressions`);; | ||
for (let i = 0; i < path.length; i++) { | ||
names[i == 0 ? `#attr${grp}` : `#attr${grp}${i}`] = i == 0 ? checkAttribute(path[i], (entity ? table[entity].schema.attributes : table.Table.attributes)) : path[i]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would be easier to understand if you used if
...else
statements rather than inlining it like this. Took me a while to read it and process how it's supposed to work.
@@ -36,13 +36,13 @@ interface FilterExpression { | |||
export type FilterExpressions = FilterExpression | FilterExpression[] | FilterExpressions[] | |||
|
|||
const buildExpression = ( | |||
exp: FilterExpressions, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There seems to be a lot of noise from your linter/EOL. Can you remove these from the PR?
@darbio thank you for the review, let me have another pass at this (it was the fastest way I could make it work at the time) I also need to add a test for this. |
Closing this PR for maintenance purposes now that the v1 is out. |
Basically I have situation where I want to use a value from map type in the schema in the check condition of a updateTransaction function call.
Entity.updateTransaction({ pk: 'TEST', id: details.id, tenantId: details.tenantId, dTimes: { $set: { 'count': { $add: -1 }}}}, { conditions: { attr: "dTimes.count", gt: 0 }})
The condition clause was being generated as
#attr1 > :attr1
This change will generate the clause as
#attr1.#attr11 > :attr1
This probably isn't the best or greatest solution but hopefully it helps explain the problem a little better.
This is a really useful library thank you for the hard work building it.