```swift do { let result = try await Amplify.DataStore.query(Post.self) // result will be of type [Post] print("Posts: \(result)") } catch let error as DataStoreError { print("Error on query() for type Post - \(error)") } catch { print("Unexpected error \(error)") } ``` ```swift let sink = Amplify.Publisher.create { try await Amplify.DataStore.query(Post.self) }.sink { if case let .failure(error) = $0 { print("Error on query() for type Post - \(error)") } } receiveValue: { result in print("Posts: \(result)") } ``` ### Query by identifier Query has an alternative signature that allows to fetch a single item by its `id`: ```swift do { let result = try await Amplify.DataStore.query(Post.self, byId: "123") // result will be a single object of type Post? print("Post: \(result)") } catch { print("Error on query() for type Post - \(error)") } ``` ```swift let sink = Amplify.Publisher.create { try await Amplify.DataStore.query(Post.self, byId: "123") }.sink { if case let .failure(error) = $0 { print("Error on query() for type Post - \(error)") } } receiveValue: { result in print("Posts: \(result)") } ```