Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Adds DynamoDB Adapter #333

Draft
wants to merge 20 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add support for delete collection / attribute
  • Loading branch information
ajwad-shaikh committed Oct 7, 2023
commit 97838a6e7d0300021a2598ea123a644d8ffa120c
26 changes: 26 additions & 0 deletions src/Database/Adapter/DynamoDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,14 @@ public function createCollection(string $name, array $attributes = [], array $in
*/
public function deleteCollection(string $name): bool
{
$name = $this->filter($name);
try {
$this->client->deleteTable([
'TableName' => "{$this->getNamespace()}_{$name}",
]);
} catch (DynamoDbException $e) {
return false;
}
return true;
}

Expand Down Expand Up @@ -338,6 +346,24 @@ public function updateAttribute(string $collection, string $id, string $type, in
*/
public function deleteAttribute(string $collection, string $id): bool
{
$collection = $this->filter($collection);
$queryParams = [
'TableName' => "{$this->getNamespace()}_{$collection}",
'ProjectionExpression' => '_id'
];
$items = ($this->client->query($queryParams))['Items'];
foreach ($items as $item) {
$updateParams = [
'TableName' => "{$this->getNamespace()}_{$collection}",
'Key' => ['_id' => $item['_id']], // Replace with your primary key
'UpdateExpression' => 'REMOVE ' . $id,
];
try {
$this->client->updateItem($updateParams);
} catch (DynamoDbException $e) {
return false;
}
}
return true;
}

Expand Down