3
3
namespace BaoPham \DynamoDb ;
4
4
5
5
use Aws \DynamoDb \DynamoDbClient ;
6
+ use Closure ;
6
7
use Exception ;
8
+ use Illuminate \Contracts \Support \Arrayable ;
7
9
use Illuminate \Database \Eloquent \Collection ;
8
10
use \Illuminate \Database \Eloquent \ModelNotFoundException ;
9
11
use Illuminate \Support \Facades \Log ;
@@ -116,7 +118,10 @@ public function where($column, $operator = null, $value = null, $boolean = 'and'
116
118
117
119
$ valueList = [$ attributeValueList ['AttributeValueList ' ]];
118
120
119
- if (strtolower ($ operator ) === 'between ' ) {
121
+ if (
122
+ ComparisonOperator::is ($ operator , ComparisonOperator::BETWEEN ) ||
123
+ ComparisonOperator::is ($ operator , ComparisonOperator::IN )
124
+ ) {
120
125
$ valueList = head ($ valueList )['L ' ];
121
126
}
122
127
@@ -128,6 +133,43 @@ public function where($column, $operator = null, $value = null, $boolean = 'and'
128
133
return $ this ;
129
134
}
130
135
136
+ /**
137
+ * Add a "where in" clause to the query.
138
+ *
139
+ * @param string $column
140
+ * @param mixed $values
141
+ * @param string $boolean
142
+ * @param bool $not
143
+ * @return $this
144
+ */
145
+ public function whereIn ($ column , $ values , $ boolean = 'and ' , $ not = false )
146
+ {
147
+ if ($ boolean != 'and ' ) {
148
+ throw new NotSupportedException ('Only support "and" in whereIn clause ' );
149
+ }
150
+
151
+ if ($ not ) {
152
+ throw new NotSupportedException ('"not in" is not a valid DynamoDB comparison operator ' );
153
+ }
154
+
155
+ // If the value is a query builder instance, not supported
156
+ if ($ values instanceof static) {
157
+ throw new NotSupportedException ('Value is a query builder instance ' );
158
+ }
159
+
160
+ // If the value of the where in clause is actually a Closure, not supported
161
+ if ($ values instanceof Closure) {
162
+ throw new NotSupportedException ('Value is a Closure ' );
163
+ }
164
+
165
+ // Next, if the value is Arrayable we need to cast it to its raw array form
166
+ if ($ values instanceof Arrayable) {
167
+ $ values = $ values ->toArray ();
168
+ }
169
+
170
+ return $ this ->where ($ column , ComparisonOperator::IN , $ values );
171
+ }
172
+
131
173
/**
132
174
* Implements the Query Chunk method
133
175
*
0 commit comments