【问题标题】:AWS-Appsync How to query latest items from the dynamoDB table?AWS-Appsync 如何从 dynamoDB 表中查询最新项目?
【发布时间】:2019-09-03 07:30:50
【问题描述】:

我刚刚开始使用 AWS Appsync,并且主要使用 GraphQL 和 SDK 方法完成了大部分教程 (https://aws-amplify.github.io/docs/js/api)。

如何查询我的 dynamoDB 表以仅返回最新的 50 篇文章?


class TestScreen extends Component {
    state = { list: [] }

    async componentDidMount() {
        const fetched = await API.graphql(graphqlOperation(queries.listArticles))
        this.setState({ 
            list: fetched.data.listArticles.items,
        })
    }

    renderRow(item) {
        return (
            <View>
                <Text>{item.name}</Text>
            </View>
        )
    }

    render() {
        return (
            <View>
                <FlatList
                    data={this.state.list}
                    renderItem={({item}) => this.renderRow(item)}
                    keyExtractor={item => item.id}
                />
            </View>
        )
    }
}

目前,查询返回给我的姓名列表,但不是按任何可识别的顺序。

【问题讨论】:

标签: reactjs react-native aws-appsync


【解决方案1】:

您可以在时间戳字段上创建secondary index 并使用它来查询表。除此之外,您还可以使用pagination

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-25
    • 2019-02-16
    • 2019-08-02
    • 2018-12-02
    • 1970-01-01
    • 2019-10-14
    • 2019-10-19
    • 2019-05-03
    相关资源
    最近更新 更多