<BlockSwitcher>

<Block name="Async/Await">

```swift
let p = Post.keys
do {
    let result = try await Amplify.DataStore.query(
        Post.self,
        where: p.rating > 4 && p.status == PostStatus.active
    )
    // result of type [Post]
    print("Published posts with rating greater than 4: \(result)")
} catch let error as DataStoreError {
    print("Error listing posts - \(error)")
} catch {
    print("Unexpected error \(error)")
}
```

</Block>

<Block name="Combine">

```swift
let p = Post.keys
let sink = Amplify.Publisher.create {
    try await Amplify.DataStore.query(
        Post.self,
        where: p.rating > 4 && p.status == PostStatus.active
    )
}.sink {
    if case let .failure(error) = $0 {
        print("Error listing posts - \(error)")
    }
}
receiveValue: { result in
    print("Published posts with rating greater than 4: \(result)")
}
```

</Block>

</BlockSwitcher>

You can also write this in a compositional function manner by replacing the operators with their equivalent predicate statements such as `.gt`, `.and`, etc:

<BlockSwitcher>

<Block name="Async/Await">

```swift
let p = Post.keys
try await Amplify.DataStore.query(
    Post.self,
    where: p.rating.gt(4).and(p.status.eq(PostStatus.active))
)
```

</Block>

<Block name="Combine">

```swift
let p = Post.keys
let sink = Amplify.Publisher.create {
    try await Amplify.DataStore.query(
        Post.self,
        where: p.rating > 4 && p.status == PostStatus.active
    )
}.sink {
    // handle result
}
```

</Block>

</BlockSwitcher>
