Skip to content

Commit 5127178

Browse files
committed
Update README.md
1 parent 3d7984f commit 5127178

File tree

1 file changed

+13
-72
lines changed

1 file changed

+13
-72
lines changed

README.md

Lines changed: 13 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ Whereas every request in PocoDynamo is invoked inside a managed execution where
290290

291291
All PocoDynamo API's returning `IEnumerable<T>` returns a lazy evaluated stream which behind-the-scenes sends multiple
292292
paged requests as needed whilst the sequence is being iterated. As LINQ API's are also lazily evaluated you could use
293-
`Take()` to only download however the exact number results you need. So you can query the first 100 table names with:
293+
`Take()` to only download the exact number results you need. So you can query the first 100 table names with:
294294

295295
```csharp
296296
//PocoDynamo
@@ -568,77 +568,6 @@ and auto-conversion of dynamic results into typed POCOs.
568568

569569
### Query Usage
570570

571-
Query's are the efficient way to Query DynamoDB since it's limited to querying indexed fields, i.e. the Hash and
572-
Range Keys on your Tables or Table Indexes. Although it has the major limitation that it always needs to specify a Hash
573-
condition, essentially forcing the query to be scoped to a single partition. This makes it especially useless for Tables
574-
with only a single Hash Primary Key like `Todo` as the query condition will always limit to a maximum of 1 result.
575-
576-
Nevertheless we can still use it to show how to perform server-side queries with PocoDynamo. To create a
577-
QueryExpression use the `FromQuery*` API's. It accepts a `KeyConditionExpression` as the first argument as it's a
578-
mandatory requirement for Query Requests which is used to identify the partition the query should be executed on:
579-
580-
```csharp
581-
var q = db.FromQuery<Todo>(x => x.Id == 1);
582-
```
583-
584-
PocoDynamo parses this lambda expression to return a populated `QueryExpression<Todo>` which you can inspect to find
585-
the `TableName` set to **Todo** and the `KeyConditionExpression` set to **(Id = :k0)** with the
586-
`ExpressionAttributeValues` Dictionary containing a Numeric value of **1** for the key **:k0**.
587-
588-
From here you can continue populating the QueryRequest DTO by calling the QueryExpression methods the names of which
589-
are modeled after the properties they populate, e.g. the `Filter()` API populates the `FilterExpression` property:
590-
591-
```csharp
592-
q.Filter(x => x.Done);
593-
```
594-
595-
After you've finished populating the Request DTO you can call PocoDynamo's `Query()` API to execute the query.
596-
This returns a lazily executed resultset which you can use LINQ methods on to fetch the results. Given the primary key
597-
condition we know this will only return 0 or 1 rows based on whether or not the TODO has been completed which we can
598-
check with by calling LINQ's `FirstOrDefault()` method:
599-
600-
```csharp
601-
var todo1 = db.Query(q).FirstOrDefault();
602-
```
603-
604-
If `todo1` was completed it will return the populated `Todo`, otherwise it will return `null`.
605-
606-
#### Expression Chaining
607-
608-
Most `QueryExpression` methods returns itself and an alternative to calling `Query` on PocoDynamo (or AWSSDK) to execute
609-
the Query, you can instead call the `Exec()` alias. This allows you to create and execute your DynamoDb Query in a
610-
single expression which could instead be rewritten as:
611-
612-
```csharp
613-
var todo1 = db.FromQuery<Todo>(x => x.Id == 1)
614-
.Filter(x => x.Done)
615-
.Exec()
616-
.FirstOrDefault();
617-
```
618-
619-
### Scan Operations
620-
621-
622-
## Supported LINQ Expressions
623-
624-
Another area where PocoDynamo adds a lot of value that can be fairly cumbersome to do without, is in creating and
625-
executing [Query and Scan](http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/QueryAndScan.html)
626-
requests to query data in DynamoDB Tables.
627-
628-
### QueryExpressions are QueryRequests
629-
630-
The query functionality in PocoDynamo is available on the `QueryExpression<T>` class which can be used as a typed query
631-
builder to construct your Query request. An important attribute of QueryExpression's is that they simply inherit AWSSDK's
632-
[QueryRequest](http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/LowLevelDotNetQuerying.html) Request DTO.
633-
634-
This provides a number of benefits, they're easy to understand and highly introspectable as each API just ends up
635-
populating fields in the base `QueryRequest` DTO. They're highly reusable where QueryExpressions can be executed as-is
636-
in both AWSSDK's DynamoDB client as well as PocoDynamo's `Query*` API's which can execute both `QueryExpression<T>` and
637-
and AWSSDK's `QueryRequest` DTOs. The difference when executing queries in PocoDynamo are that they provide managed
638-
execution, lazily evaluated streaming results, paged queries and auto-conversion of unstructured results into typed POCOs.
639-
640-
### Query Usage
641-
642571
[DynamoDB Query's](http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Query.html) enable efficient
643572
querying of data in DynamoDB as it's limited to querying the indexed Hash and Range Keys on your Tables or Table Indexes.
644573
Although it has the major limitation that it always needs to specify a Hash condition, essentially forcing the query
@@ -704,6 +633,18 @@ var todo1Done = db.FromQuery<Todo>(x => x.Id == 1)
704633
.FirstOrDefault();
705634
```
706635

636+
### Scan Operations
637+
638+
Scan Operations work very similar to Query Operations but instead of using a `QueryExpression<T>` you would instead use a `ScanExpression<T>` which as it inherits from AWSSDK's `ScanRequest` Request DTO, provides the same reuse benefits as QueryExpression's.
639+
640+
To create a Scan Request you would use the `FromScan<T>` API, e.g:
641+
642+
```csharp
643+
var q = db.FromScan<Todo>();
644+
```
645+
646+
More examples of how to use typed LINQ expressions for creating and executing Query and Scan requests are described later.
647+
707648
### Related Items
708649

709650
DynamoDB Queries are ideally suited for when the dataset is naturally isolated, e.g. multi-tenant Apps that are

0 commit comments

Comments
 (0)