Skip to content

Commit c880aac

Browse files
committed
Update README.md
1 parent 5352454 commit c880aac

File tree

2 files changed

+73
-10
lines changed

2 files changed

+73
-10
lines changed

CLAUDE.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Commands
6+
7+
### Testing
8+
- Run all tests: `./vendor/bin/phpunit`
9+
- Run a single test: `vendor/bin/phpunit tests/Path/To/TestFile.php`
10+
- Run a single test method: `vendor/bin/phpunit --filter testMethodName`
11+
12+
### Development
13+
- Install dependencies: `composer install`
14+
- Update dependencies: `composer update`
15+
16+
## Architecture Overview
17+
18+
This is a Laravel package that provides DynamoDB integration by adapting Laravel's database layer to work with AWS DynamoDB.
19+
20+
### Key Design Patterns
21+
22+
1. **Adapter Pattern**: The package adapts Laravel's database abstractions to DynamoDB
23+
- `Connection` extends Laravel's base connection class
24+
- `Model` extends Eloquent with DynamoDB-specific behavior
25+
- Query results are processed through `Processor` to match Laravel's expectations
26+
27+
2. **Builder Pattern**: DynamoDB queries are constructed using a fluent interface
28+
- `Query\Builder` provides chainable methods
29+
- Separate query objects for different DynamoDB operations (filter, condition, keyCondition)
30+
- `ExpressionAttributes` manages placeholder generation for expressions
31+
32+
3. **Grammar Translation**: `Query\Grammar` translates Laravel-style queries to DynamoDB API format
33+
- Uses AWS Marshaler for type conversions
34+
- Compiles expressions using DynamoDB syntax
35+
- Handles reserved words and attribute name conflicts
36+
37+
### Important Architectural Decisions
38+
39+
- **No Eloquent Relationships**: Models intentionally don't support relationships as DynamoDB is NoSQL
40+
- **Primary Keys**: Models require `primaryKey` and optionally `sortKey` properties
41+
- **Authentication**: Custom `AuthUserProvider` supports both primary key and API token authentication using DynamoDB indexes
42+
- **Batch Operations**: Native support for DynamoDB batch operations (batchGetItem, batchPutItem, etc.)
43+
- **Testing**: Use `dryRun()` method to inspect generated DynamoDB parameters without making API calls
44+
45+
### Testing Approach
46+
47+
Tests use Mockery to mock AWS SDK calls. When writing tests:
48+
- Mock the DynamoDB client for unit tests
49+
- Use `dryRun()` to test query building without API calls
50+
- Follow existing test patterns in the `tests/` directory
51+
52+
### Version Compatibility
53+
54+
- PHP: 7.3, 7.4, 8.0, 8.1, 8.2, 8.3, 8.4
55+
- Laravel: 6.x through 12.x
56+
- AWS SDK: ^3.0

README.md

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ Install the package via Composer:
8282
$ composer require kitar/laravel-dynamodb
8383
```
8484

85-
### Laravel (6.x, 7.x, 8.x, 9.x, 10.x, 11.x)
85+
### Laravel (6.x, 7.x, 8.x, 9.x, 10.x, 11.x, 12.x)
8686

8787
Add dynamodb configs to `config/database.php`:
8888

@@ -110,6 +110,14 @@ Update the `DB_CONNECTION` variable in your `.env` file:
110110
DB_CONNECTION=dynamodb
111111
```
112112

113+
> **Note for Laravel 11+**: Laravel 11 and later versions default to `database` driver for session, cache, and queue, which are not compatible with this DynamoDB package. You'll need to configure these services to use alternative drivers. For instance:
114+
>
115+
> ```
116+
> SESSION_DRIVER=file
117+
> CACHE_STORE=file
118+
> QUEUE_CONNECTION=sync
119+
> ```
120+
113121
### Non-Laravel projects
114122
115123
For usage outside Laravel, you can create the connection manually and start querying with [Query Builder](#query-builder).
@@ -397,7 +405,7 @@ Then specify driver and model name for authentication in `config/auth.php`.
397405

398406
### Registration Controller
399407

400-
You might need to modify the registration controller. For example, if we use Laravel Breeze, the modification looks like below.
408+
You might need to modify the registration controller. For example, if we use Laravel Starter Kits, the modification looks like below.
401409

402410
```php
403411
class RegisteredUserController extends Controller
@@ -408,31 +416,30 @@ class RegisteredUserController extends Controller
408416
{
409417
$request->validate([
410418
'name' => 'required|string|max:255',
411-
'email' => ['required', 'string', 'email', 'max:255', function ($attribute, $value, $fail) {
419+
'email' => ['required', 'string', 'lowercase', 'email', 'max:255', function ($attribute, $value, $fail) {
412420
if (User::find($value)) {
413421
$fail('The '.$attribute.' has already been taken.');
414422
}
415423
}],
416-
'password' => 'required|string|confirmed|min:8',
424+
'password' => ['required', 'confirmed', Rules\Password::defaults()],
417425
]);
418426

419-
$user = new User([
427+
$user = User::create([
420428
'name' => $request->name,
421429
'email' => $request->email,
422430
'password' => Hash::make($request->password),
423431
]);
424-
$user->save();
425-
426-
Auth::login($user);
427432

428433
event(new Registered($user));
429434

430-
return redirect(RouteServiceProvider::HOME);
435+
Auth::login($user);
436+
437+
return to_route('dashboard');
431438
}
432439
}
433440
```
434441

435-
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.
442+
The change is in the email validation rules. Instead of using the `unique` rule, we pass a closure to perform the duplicate check directly.
436443

437444
## Query Builder
438445

0 commit comments

Comments
 (0)