-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
How to save array of objects in datastore #5099
Comments
Hi @apoorvmote Thanks for the feedback,
This seems to be an error in the typescript definition. I'll be labeling this issue as a bug. Now, internally, the storage adapters return that array and we use it for book keeping purposes, it shouldn't be in the public facing API Now, regarding your question:
The answer would be with a regular loop, e.g. |
Any chance that we CAN do batch saves now? Or still individual saves? |
Same here , it would be great to do batch saves! |
I got tired of waiting around for this feature and actually since launch of HTTP api its cheaper to use the HTTP API + Lambda for batch save. You will lose benefit of graphql mutation triggering subscription notification but batch save is possible with HTTP API. |
Hi @apoorvmote , IMHO since you save first on local the performance is not too bad (maybe it's because the size of the DB is relatively small) |
I personally use react-query and you can also try swr from vercel. Its not perfect solution but for now it works. In future I would create websocket connection how github does it when you write comment and if I am on same page then the page refreshes with your comment. |
This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs. Looking for a help forum? We recommend joining the Amplify Community Discord server |
Which Category is your question related to?
Datastore
What AWS Services are you utilizing?
Cognito, AWS AppSync, Datastore
Provide additional details e.g. code snippets
This is really stupid
const results = await DataStore.save(new User({name: 'John'}))
this returns
User[]
So you would naturally assume that you can save multiple users at once.But following creates an error.
const results = await DataStore.save(new User({name: 'John'}), new User({name: 'Jane'}))
or
const results = await DataStore.save([new User({name: 'John'}), new User({name: 'Jane'})])
or
const results = await DataStore.save(new User({name: 'John'}, {name: 'Jane'}))
why bother returning
User[]
if you are allowing to save only one item at a time?Also I used wrong example but for real world use case think of array of invoice items to be added to single invoice.
The text was updated successfully, but these errors were encountered: