Download the PHP package nham24/laravel-dynamodb without Composer

On this page you can find all versions of the php package nham24/laravel-dynamodb. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-dynamodb

Laravel DynamoDB

This package is just a fork of kitar/laravel-dynamodb to support laravel 5.8. If your project is using laravel 6+, you should use kitar/laravel-dynamodb instead.

test codecov

A DynamoDB based Eloquent model and Query builder for Laravel.

Motivation

Installation

Install the package via Composer:

Laravel

We only support Laravel >= 5.8.

Add dynamodb configs to config/database.php:

Non-Laravel projects

For usage outside Laravel, you can create the connection manually and start querying with Query Builder.

Sample data

Many of the example codes in this document are querying to DynamoDB's official sample data. If you want to try these codes with actual DynamoDB tables, it's handy to load them to your tables before.

Model

DynamoDB model extends Eloquent model so that we can use familiar features such as mutators, serialization, etc.

The main difference between Eloquent model and DynamoDB model is:

Extending the base model

Most of the attributes are the same as the original Eloquent model, but there are few DynamoDB-specific attributes.

Name Required Description
table yes Name of the Table.
primaryKey yes Name of the Partition Key.
sortKey Name of the Sort Key.
sortKeyDefault Default value for the Sort Key.

For example, if our table has only partition key, the model will look like this:

If our table also has sort key:

If we set sortKeyDefault, it will be used when we instantiate or call find without sort key.

Note that this model is implementing Illuminate\Contracts\Auth\Authenticatable and using Illuminate\Auth\Authenticatable. This is optional, but if we use them, we can use this model with authentication as well. For authentication, please refer to Authentication section) for more details.

Basic Usage

Retrieving all models

or alternatively,

DynamoDB can only handle result set up to 1MB per call, so we have to paginate if there are more results. see Paginating the Results for more details.

Retrieving a model

If the model has only partition key:

If the model also has sort key:

If the model has sort key and sortKeyDefault is defined:

save()

update()

delete()

increment() / decrement()

When we call increment() and decrement(), the Atomic Counter will be used under the hood.

We can also pass additional attributes to update.

Advanced Queries

We can use Query Builder functions through model such as query scan filter condition keyCondition etc.

For example:

Please refer to Query Builder for the details.

Authentication with model

We can create a Custom User Provider to authenticate with DynamoDB. For the detail, please refer to Laravel's official document.

To use authentication with the model, the model should implement Illuminate\Contracts\Auth\Authenticatable contract. In this section, we'll use the example User model above.

Register custom user provider

After we prepare authenticatable model, we need to make the custom user provider. We can make it own (it's simple), but we'll use Kitar\Dynamodb\Model\AuthUserProvider in this section.

To register custom user provider, add codes below in App/Providers/AuthServiceProvider.php.

Change auth config

Then specify driver and model name for authentication in config/auth.php.

api_token_name and api_token_index are optional, but we need them if we use api token authentication.

Registration Controller

You might need to modify the registration controller. For example, if we use Laravel Breeze, the modification looks like below.

There are two modifications. The first one is adding the closure validator for email instead of unique validator. The second one is using the save() method to create user instead of the create() method.

Query Builder

We can use Query Builder without model.

Or even outside Laravel.

If we query through the model, we don't need to specify the table name, and the response will be the model instance(s).

Basic Usage

getItem()

Instead of marshaling manually, pass a plain array. Kitar\Dynamodb\Query\Grammar will automatically marshal them before querying.

putItem()

updateItem()

Currently, we only support simple SET and REMOVE actions. If the attribute has value, it will be passed to SET action. If the value is null, it will be passed to REMOVE action.

deleteItem()

Projection Expressions

A Projection Expression is a string that identifies the attributes that web want. (It's like select statement for SQL)

select()

We can specify Projection Expressions in the same manner as the original select clause.

Condition Expressions

When we manipulate data in Amazon DynamoDB table, we use putItem, updateItem and DeleteItem. We can use Condition Expressions to determine which items should be modified.

condition()

To specify Condition Expression, we use condition clause. This works basically same as the original where clause, but it's for Condition Expressions.

Note that we specify attribute_not_exists for the operator of condition. This is DynamoDB-specific operator which called function. See DynamoDB-specific operators for condition() and filter() for more details.

OR statements

AND statements

conditionIn()

conditionBetween()

Working with Queries

The Query operation in Amazon DynamoDB finds items based on primary key values.

query() and keyCondition()

When we query, we must specify keyCondition as well.

We can use some comparison operators for sort key, but we must use the equality condition for the partition key.

keyConditionBetween()

Working with Scans

scan()

Filtering the Results

When we query or scan, we can filter results with Filter Expressions before it returned.

It can't reduce the amount of read capacity, but it can reduce the size of traffic data.

filter()

OR statement

AND statement

filterIn()

filterBetween()

Paginating the Results

A single query or scan only returns a result set that fits within the 1 MB size limit. If there are more results, we need to paginate.

exclusiveStartKey()

If there are more results, the response contains LastEvaluatedKey.

We can pass this key to exclusiveStartKey to get next results.

If you are using Query Builder through model, you can access to exclusiveStartKey by:

Using Global Secondary Indexes

Some applications might need to perform many kinds of queries, using a variety of different attributes as query criteria. To support these requirements, you can create one or more global secondary indexes and issue query requests against these indexes in Amazon DynamoDB.

index()

Use index clause to specify Global Secondary Index name.

Atomic Counter

DynamoDB supports Atomic Counter. When we call increment() and decrement() through Model or Query Builder, Atomic Counter will be used under the hood.

We can also pass additional attributes to update.

DynamoDB-specific operators for condition() and filter()

For condition and filter clauses, we can use DynamoDB's comparators and functions.

Comparators

= <> < <= > >= can be used in the form of:

functions

Available functions are:

size function is not supported at this time.

Testing


All versions of laravel-dynamodb with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
illuminate/support Version ^9.0
illuminate/container Version ^9.0
illuminate/database Version ^9.0
illuminate/hashing Version ^9.0
aws/aws-sdk-php Version ^3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package nham24/laravel-dynamodb contains the following files

Loading the files please wait ....