File tree Expand file tree Collapse file tree 4 files changed +21
-2
lines changed Expand file tree Collapse file tree 4 files changed +21
-2
lines changed Original file line number Diff line number Diff 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 ...
Original file line number Diff line number Diff 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 /**
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments