oasmobile / php-dynamodb-odm

ODM for dynamodb
MIT License
13 stars 18 forks source link

Query return only 30 objects #4

Closed tfe2012 closed 7 years ago

tfe2012 commented 7 years ago

Can you add to description, how to change query limits

tfe2012 commented 7 years ago

Or how Paginate result?

no7mks commented 7 years ago

Most, if not all, AWS services use a next-key variable to implement pagination. i.e., you pass a next-key by reference to query functions, with the initial value set to null, and loop whenever this key is set to something other than null by the query functions.

e.g.:

$result = [];
do {
    $page = $im->getRepository(User::class)->query(
        "#hashKey = :hk AND #sortKey > :min",
        [
            ":hk" => "abc",
            ":min" => 10,
        ],
        '',
        $lastKey
    );
    $result = array_merge($result, $page);
} while ($lastKey);
tfe2012 commented 7 years ago

Maybe you can add this information to ODM tutorial ?

How about pagination?

If you want create data table.

no7mks commented 7 years ago

fixed page-size pagination is not directly supported by DynamoDB, nor can it be supported by ODM. (partly bcz DynamoDB's evaluationLimit parameter is not same as returned page size)

check how facebook, twitter and many modern websites handle pagination in their main news feed page. There is no traditional "pagination", but constantly fetching something more, based on a last-fetched-record. This is quite similar to what DynamoDB supports.

So, if you would like to have old-school pagination, try the following methods:

tfe2012 commented 7 years ago

Send query without 'indexName'

"#hashKey = :hk AND #sortKey > :min", [ ":hk" => "abc", ":min" => 10, ], '', $lastKey

It's impossible , you get

InvalidArgumentException

no7mks commented 7 years ago

I'm sorry, it should be an idx name for GSI, or DynamoDbIndex::PrimaryIndex as default

tfe2012 commented 7 years ago

What about boolean type?

This is my query. But you can't create boolean index in dynamodb console ->query( "#done = :done", [ ":done" => false, ], 'done-index', $lastKey );

no7mks commented 7 years ago

you are right, you can't create boolean types in dynamodb index. and as a result, you can't query for boolean values. However, you can still use scan() with boolean type for non-indexed search.

tfe2012 commented 7 years ago

Can you give me code example ?

no7mks commented 7 years ago

The readme.md already shows simple use of scan() method.

Furthermore, I am not sure how familiar you know about DynamoDB. I suggest you fully read AWS' DynamoDB's dev-guide first, because that explains a lot more what DynamoDB is and what DynamoDB can do. ODM doesn't offer more than DynamoDB's ability, and many concepts are strongly based on DynamoDB's convention. (Like the difference between query/scan)

tfe2012 commented 7 years ago

Thx, I find