Comments (9)
Pagination isn't supported right now. But try chunk
- it's the closest thing to pagination depending on your needs?
from laravel-dynamodb.
Oops, closing to soon. I will mark this as a feature request.
Pagination isn't supported but I would love to have it implemented. PR is welcome of course.
Related issue: #15
from laravel-dynamodb.
Pagination is supported in DynamoDB in the form of LastEvaluatedKey
in the result set and ExclusiveStartKey
when making a query or scan. See http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/QueryAndScan.html#Pagination
from laravel-dynamodb.
Yep. We just need to get it in here :)
from laravel-dynamodb.
A step forward for pagination?
https://github.com/baopham/laravel-dynamodb/compare/master...zoul0813:feature/skip-offset?expand=1
I added support for skip
/offset
and introduced setLastEvaluatedKey
to the QueryBuilder. I also refactored the getCompositeKey
method and added getCompositeKeyName
to match the Eloquent getKey
and getKeyName
methods.
This doesn't introduce pagination, but allows you to use the primaryKey/compositeKey of a model to "skip".
For example, when calling chunk to walk through large datasets ... in the event of an error (ie; provisioned capacity issues) you can use the primaryKey/compositeKey of the last model evaluated as the lastEvaluatedKey and call chunk again, skipping anything you've already gone through.
I'm using this in a custom artisan command to reindex my DynamoDB Items in ElasticSearch. I occasionally run into provisioned capacity errors, and introducing this skip/offset modification has allowed me to "resume" after an error without having to go through all the items I've already processed.
Example of my "elasticsearch:reindex" command, taking advantage of "skip". I output the current models primaryKey/compositeKey values to the console so I can copy/paste them and pass them to the "--skip" parameter of the command to "resume".
<?php
namespace App\Console\Commands;
use Illuminate\Support\Facades\App;
use Illuminate\Console\Command;
use Exception;
class ElasticSearchReindex extends Command
{
protected $signature = 'elasticsearch:reindex {model} {--size=100} {--rebuild} {--skip=*}';
protected $description = 'DynamoDB Table Clear';
public function handle()
{
$model = 'App\\' . $this->argument('model');
$pageSize = (int)$this->option('size');
$skip = $this->option('skip', null);
$rebuild = filter_var($this->option('rebuild', false), FILTER_VALIDATE_BOOLEAN);
if(!class_exists($model)) {
$this->error('Invalid Class: ' . $model);
die();
}
if($rebuild) {
try {
$this->warn('Deleting and rebuilding index');
$model::deleteIndex();
$model::createIndex();
$model::putMapping();
$this->info("Index Rebuilt (delete, create, put)");
} catch(Exception $e) {
$this->error($e->getMessage());
die();
}
}
// if $skip is empty, then lastEvaluatedKey is set to null
$query = $model::skip($skip);
$this->warn('pageSize: ' . $pageSize . ', skipping: ' . print_r($skip, true) . ', lastEvaluatedKey: ' . print_r($query->getLastEvaluatedKey(), true));
try {
$query->chunk($pageSize, function($models) {
static $total = 0;
$this->info('Total: ' . $total . ', Found: ' . count($models));
foreach($models as $item) {
try {
$item->addToIndex();
$this->line('Indexed: ' . $item->getKey() . ', ' . json_encode($item->getCompositeKey()) . ', ' . json_encode($item->getCompositeKeyValue()));
} catch(Exception $e) {
$this->error("EXCEPTION: " . $item->getKey() . ', ' . $e->getMessage() . ")");
}
}
$total += count($models);
});
} catch(Exception $e) {
$this->error("EXCEPTION: " . $e->getMessage());
}
}
}
@baopham I can create a PR if you'd like ...
from laravel-dynamodb.
yep please go ahead.
from laravel-dynamodb.
Any progress on this?
from laravel-dynamodb.
No, no update yet. During the holidays, I should have more time to look into it.
from laravel-dynamodb.
@Saracevas pagination is now added. You can try v4.0.0. Please check README, since it's DynamoDB so we cannot match exactly with the same concept as relational DB.
from laravel-dynamodb.
Related Issues (20)
- How to connect DynamoDB via VPC endpoint HOT 1
- Combination of wherIn() and update() not working HOT 2
- I can't sort the items on a query HOT 3
- Could you fix this code? (PHP5.6 FatalError Analyzer.php ) HOT 1
- Issue using Nested attributes HOT 1
- Could I use AssumeRole with baopham dynamodb? HOT 2
- Force KeyCondition when filtering by only partition key in a table with a composite key HOT 1
- Add DAX Client HOT 1
- Pagination HOT 3
- DynamoDbModel constructor is not calling the `initializeTraits()` method like the parent HOT 1
- Unable to update data using where() HOT 6
- dynamodb.php not recognized HOT 1
- How to use 'Sort descending'
- How to query List\Map Key-Value field HOT 2
- Invalid Query or Scan syntax with "single-table design" indexes HOT 1
- How can we use API resources?
- Expecting RequestInterface, given RulesetEndpoint HOT 6
- Cannot access property/attribute of returned record HOT 2
- get() with a non-existent value as the primary key using where returns a collection with null instead of an empty collection
- Laravel 11 support HOT 12
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-dynamodb.