Reputation: 4136
I have this data model:
const schema = a.schema({
Messages: a
.model({
Timestamp: a.string().required(),
From: a.string().required(),
To: a.string().required(),
Body: a.string().required(),
])
});
I want to query it and display the latest 10 messages, and paginate to display older messages.
How can I achieve that?
I tried adding:
.model({
...
Dummy: a.integer().default(0),
}).secondaryIndexes(index => [
index('Dummy').sortKeys(['Timestamp']).queryField('listByTimestamp')
])
But then listByTimestamp()
doesn't have a limit
argument as in simple list()
.
Upvotes: 1
Views: 68
Reputation: 151
Looks like it has to come as options in the second argument when using the listBy* queries.
E.g.
client.model.Messages.listByTimestamp({
// fields you need
}, {
limit: 10,
nextToken: nextToken,
sortDirection: "DESC"
});
Upvotes: 0