Skip to content

How to query last inserted item? #340

Answered by tywalch
meightythree asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @meightythree 👋

Two things here:

Thing 1

Your syntax is nearly correct, the correct syntax would be the following:

await MyEntity.scan.go({ limit: 1, order: 'desc' });

The params and go methods are two ways to terminate an operation (terminal methods). The params terminal method synchronously returns DynamoDB JSON parameters for a given operation, while the go terminal method executes the operation. In the above example I would either call params or go but not both. You can find more information about those methods here: https://electrodb.dev/en/core-concepts/executing-queries/#execution-methods

Thing 2

I'm glad you shared your full intent because I don't believe this query will actual…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by meightythree
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants