-
Hello, I appreciate all the work you put into onetable development! I've been having some trouble executing update command on my model. My data in JSON format looks like this:
What I want is to set processed to true on slides[4SWys5q0BhHOiTxlRbBsK].processed. Basically I have to execute the following update statement from aws-sdk using Onetable:
Can you please point me into the right direction how can I execute that update command with Onetable? I know there is this example of updating nested fields:
but I didn't have any luck with doing it like (the reason why slides isn't an array but an object is because I wouldn't be able to update a specific field of a specific object inside the array as far as I know, please let me know if I'm wrong) Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 10 replies
-
This works for me: Model:
Code:
|
Beta Was this translation helpful? Give feedback.
-
Can you look at test/debug.ts to see if you can see a difference. I tested with jest debug. Did you get the same error message? What happened? |
Beta Was this translation helpful? Give feedback.
-
Thanks. Got it. The reason is that your '4SWys5q0BhHOiTxlRbBsK' is not a property defined in the schema. i.e. not named. The current code supports named properties and one last trailing unnamed property. I'll see if this can be fixed. |
Beta Was this translation helpful? Give feedback.
-
Wait on. I've got your create and schema code wrong. Should be slides just as an object with no nested schema.
Then the code should be
Then there is a fix in Expression.js to make it work for mult-level set expressions like yours. We'll apply this fix:
|
Beta Was this translation helpful? Give feedback.
-
I have the following schema const PermissionsSchema = {
fields: {
pk: { type: String, value: '${typename}#${resource}' },
sk: { type: String, value: '${typename}#${subject}' },
typename: { type: String },
resource: { type: String },
subject: { type: String },
policies: { type: Object }
}
}; and running the following update command, what I really want is that each time I call the async set(resource: string, subject: string, policies: Policies) {
const set = Object.fromEntries(
Object.entries(policies).map(([key, value]) => ['policies.' + key, value])
);
return await this.model.update({ resource, subject }, { set, exists: null });
} but this is not working, the response of this is an object without policies field, looks like it is completly ignoring the this is the log for the update operation
|
Beta Was this translation helpful? Give feedback.
-
@mobsense got it, it has to do with |
Beta Was this translation helpful? Give feedback.
Wait on.
I've got your create and schema code wrong. Should be slides just as an object with no nested schema.
Then the code should be