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:
88
88
'token' => env('AWS_SESSION_TOKEN'),
89
89
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
90
90
'endpoint' => env('DYNAMODB_ENDPOINT'),
91
+ 'prefix' => 'table_prefix_',
91
92
],
92
93
93
94
...
Original file line number Diff line number Diff line change @@ -19,6 +19,8 @@ public function __construct($config)
19
19
{
20
20
$ this ->client = $ this ->createClient ($ config );
21
21
22
+ $ this ->tablePrefix = $ config ['prefix ' ] ?? '' ;
23
+
22
24
$ this ->useDefaultPostProcessor ();
23
25
24
26
$ this ->useDefaultQueryGrammar ();
@@ -119,7 +121,7 @@ protected function getDefaultPostProcessor()
119
121
*/
120
122
protected function getDefaultQueryGrammar ()
121
123
{
122
- return new Query \Grammar ();
124
+ return $ this -> withTablePrefix ( new Query \Grammar () );
123
125
}
124
126
125
127
/**
Original file line number Diff line number Diff line change @@ -55,7 +55,7 @@ public function __construct()
55
55
public function compileTableName ($ table_name )
56
56
{
57
57
return [
58
- 'TableName ' => $ table_name
58
+ 'TableName ' => $ this -> tablePrefix . $ table_name
59
59
];
60
60
}
61
61
Original file line number Diff line number Diff line change @@ -974,4 +974,20 @@ public function it_can_forward_call_to_unknown_method()
974
974
975
975
$ query ->filterNotIn (['foo ' , 'bar ' ]);
976
976
}
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
+ }
977
993
}
You can’t perform that action at this time.
0 commit comments