Download the PHP package betalabs/dynamodb without Composer
On this page you can find all versions of the php package betalabs/dynamodb. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package dynamodb
laravel-dynamodb
Supports all key types - primary hash key and composite keys.
For advanced users only. If you're not familiar with Laravel, Laravel Eloquent and DynamoDB, then I suggest that you get familiar with those first.
Breaking changes in v2: config no longer lives in config/services.php
- Install
- Usage
- find() and delete()
- Conditions
- all() and first()
- Pagination
- updateAsync()
- saveAsync()
- deleteAsync()
- chunk
- limit() and take()
- firstOrFail()
- findOrFail()
- refresh()
- Query scope
- REMOVE — Deleting Attributes From An Item
- toSql() Style
- Decorate Query
- Indexes
- Composite Keys
- Query Builder
- Requirements
- Migrate from v1 to v2
- FAQ
- License
- Author and Contributors
Install
-
Composer install
-
Install service provider:
-
Run
- Update DynamoDb config in config/dynamodb.php
For Lumen
-
Try this to install the
vendor:publish
command - Load configuration file and enable Eloquent support in
bootstrap/app.php
:
Usage
- Extends your model with
BaoPham\DynamoDb\DynamoDbModel
, then you can use Eloquent methods that are supported. The idea here is that you can switch back to Eloquent without changing your queries. - Or if you want to sync your DB table with a DynamoDb table, use trait
BaoPham\DynamoDb\ModelTrait
, it will call aPutItem
after the model is saved. - Alternatively, you can use the query builder facade to build more complex queries.
- AWS SDK v3 for PHP uses guzzlehttp promises to allow for asynchronous workflows. Using this package you can run eloquent queries like save asynchronously on DynamoDb.
Supported features:
find() and delete()
Conditions
whereNull() and whereNotNull()
NULL and NOT_NULL only check for the attribute presence not its value being null
See: http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Condition.html
all() and first()
Pagination
Unfortunately, offset of how many records to skip does not make sense for DynamoDb. Instead, provide the last result of the previous query as the starting point for the next query.
Examples:
For query such as:
Take the last item of this query result as the next "offset":
update()
updateAsync()
save()
saveAsync()
Saving single model asynchronously and waiting on the promise for completion.
Saving multiple models asynchronously and waiting on all of them simultaneously.
delete()
deleteAsync()
chunk()
limit() and take()
firstOrFail()
findOrFail()
refresh()
Query Scope
REMOVE — Deleting Attributes From An Item
toSql() Style
For debugging purposes, you can choose to convert to the actual DynamoDb query
where $raw
is an instance of RawDynamoDbQuery
Decorate Query
Use decorate
when you want to enhance the query. For example:
To set the order of the sort key:
To force to use "Query" instead of "Scan" if the library fails to detect the correct operation:
Indexes
If your table has indexes, make sure to declare them in your model class like so
Note that order of index matters when a key exists in multiple indexes.
For example, we have this
with
will use count_index
.
will use user_index
.
Most of the time, you should not have to do anything but if you need to use a specific index, you can specify it like so
Composite Keys
To use composite keys with your model:
-
Set
$compositeKey
to an array of the attributes names comprising the key, e.g. - To find a record with a composite key
Query Builder
Use DynamoDb
facade to build raw queries
The query builder methods are in the form of set<key_name>
, where <key_name>
is the key name of the query body to be sent.
For example, to build an UpdateTable
query:
Do:
And when ready:
Requirements
Laravel ^5.1
Migrate from v1 to v2
Follow these steps:
- Update your
composer.json
to use v2 - Run
composer update
- Run
php artisan vendor:publish
- Move your DynamoDb config in
config/services.php
to the new config fileconfig/dynamodb.php
as one of the connections- Move
key
,secret
,token
insidecredentials
- Rename
local_endpoint
toendpoint
- Remove
local
field
- Move
FAQ
Q: Cannot assign id
property if its not in the fillable array
A: Try this?
Q: How to create migration?
A: Please see this issue
Q: How to use with factory?
A: Please see this issue
Q: How do I use with Job? Getting a SerializesModels error
A: You can either write your own restoreModel or remove the SerializesModels
trait from your Job.
Author and Contributors
All versions of dynamodb with dependencies
illuminate/support Version 5.1.* || 5.2.* || 5.3.* || 5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.* || ^6.0 || ^7.0 || ^8.0 || ^9.0
illuminate/database Version 5.1.* || 5.2.* || 5.3.* || 5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.* || ^6.0 || ^7.0 || ^8.0 || ^9.0