Skip to content

Commit 0dab354

Browse files
authored
Merge pull request #12 from sekoyadigital/feature/prefix
Support prefixes
2 parents 0ddfdb3 + 99d1b5e commit 0dab354

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ Add dynamodb configs to config/database.php:
8888
'token' => env('AWS_SESSION_TOKEN'),
8989
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
9090
'endpoint' => env('DYNAMODB_ENDPOINT'),
91+
'prefix' => 'table_prefix_',
9192
],
9293

9394
...

src/Kitar/Dynamodb/Connection.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public function __construct($config)
1919
{
2020
$this->client = $this->createClient($config);
2121

22+
$this->tablePrefix = $config['prefix'] ?? '';
23+
2224
$this->useDefaultPostProcessor();
2325

2426
$this->useDefaultQueryGrammar();
@@ -119,7 +121,7 @@ protected function getDefaultPostProcessor()
119121
*/
120122
protected function getDefaultQueryGrammar()
121123
{
122-
return new Query\Grammar();
124+
return $this->withTablePrefix(new Query\Grammar());
123125
}
124126

125127
/**

src/Kitar/Dynamodb/Query/Grammar.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function __construct()
5555
public function compileTableName($table_name)
5656
{
5757
return [
58-
'TableName' => $table_name
58+
'TableName' => $this->tablePrefix . $table_name
5959
];
6060
}
6161

tests/Query/BuilderTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,4 +974,20 @@ public function it_can_forward_call_to_unknown_method()
974974

975975
$query->filterNotIn(['foo', 'bar']);
976976
}
977+
978+
/** @test */
979+
public function it_returns_prefixed_builder()
980+
{
981+
$connection = new Connection(['prefix' => 'my_table_prefix_']);
982+
983+
$result = $connection
984+
->table('some_table')
985+
->dryRun()
986+
->getItem(['id' => 'hello']);
987+
988+
$this->assertEquals(
989+
'my_table_prefix_some_table',
990+
$result['params']['TableName']
991+
);
992+
}
977993
}

0 commit comments

Comments
 (0)