1
|
|
|
<?php |
2
|
|
|
namespace Hoooklife\DynamodbPodm\Grammars; |
3
|
|
|
use Aws\DynamoDb\Marshaler; |
4
|
|
|
use Hoooklife\DynamodbPodm\DB; |
5
|
|
|
use Hoooklife\DynamodbPodm\Query\Builder; |
6
|
|
|
|
7
|
|
|
class DynamoDBGrammar { |
8
|
|
|
protected $operators = []; |
9
|
|
|
|
10
|
|
|
protected $params = []; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @var Builder |
14
|
|
|
*/ |
15
|
|
|
private $builder; |
16
|
|
|
/** |
17
|
|
|
* @var array |
18
|
|
|
*/ |
19
|
|
|
private $config; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* DynamoDBGrammar constructor. |
23
|
|
|
* @param Builder $builder |
24
|
|
|
* @param array $config |
25
|
|
|
*/ |
26
|
|
|
public function __construct(Builder $builder, array $config) |
27
|
|
|
{ |
28
|
|
|
$this->builder = $builder; |
29
|
|
|
$this->config = $config; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
// 葨达εΌθ§£ζ where |
33
|
|
|
public function parseKeyConditionExpression(){ |
34
|
|
|
$expression = []; |
35
|
|
|
foreach ($this->builder->wheres as $where) { |
36
|
|
|
$expression[] = "{$where['column']} {$where['operator']} {$where['value']}"; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
return implode("and", $expression); |
40
|
|
|
|
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
// select |
44
|
|
|
public function parseProjectionExpression() |
45
|
|
|
{ |
46
|
|
|
if( reset($this->builder->columns) != '*' ){ |
47
|
|
|
return implode(",", $this->columns); |
|
|
|
|
48
|
|
|
} |
49
|
|
|
return null; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
// limit |
53
|
|
|
public function parseLimit(){ |
54
|
|
|
return $this->builder->limit; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Get the grammar specific operators. |
59
|
|
|
* |
60
|
|
|
* @return array |
61
|
|
|
*/ |
62
|
|
|
public function getOperators() |
63
|
|
|
{ |
64
|
|
|
return $this->operators; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function all() |
68
|
|
|
{ |
69
|
|
|
$dynamodb = new \Aws\DynamoDb\DynamoDbClient($this->config["S3Config"]); |
70
|
|
|
|
71
|
|
|
// var_dump((new Marshaler())->marshalItem([ |
72
|
|
|
// ':title'=>'aaa' |
73
|
|
|
// ])); |
74
|
|
|
// var_dump((new Marshaler())->marshalJson(' |
75
|
|
|
// { |
76
|
|
|
// ":title": "aaa" |
77
|
|
|
// } |
78
|
|
|
// ')); |
79
|
|
|
// die; |
80
|
|
|
$params = [ |
81
|
|
|
'TableName' => $this->builder->table, |
82
|
|
|
'KeyConditionExpression' => 'title = :title', |
83
|
|
|
'FilterExpression' => 'title = :title', |
84
|
|
|
'ExpressionAttributeValues'=> (new Marshaler())->marshalItem([ |
85
|
|
|
':title'=>'The Big New Movie' |
86
|
|
|
]) |
87
|
|
|
]; |
88
|
|
|
|
89
|
|
|
$result = $dynamodb->scan($params); |
90
|
|
|
|
91
|
|
|
var_dump($result); |
|
|
|
|
92
|
|
|
} |
93
|
|
|
} |