7
7
use Illuminate \Database \Query \Builder as BaseBuilder ;
8
8
use Illuminate \Database \Query \Expression ;
9
9
use Illuminate \Support \Arr ;
10
+ use Illuminate \Support \Carbon ;
10
11
use Illuminate \Support \Collection ;
11
12
use Illuminate \Support \LazyCollection ;
12
13
use Illuminate \Support \Str ;
@@ -140,7 +141,7 @@ public function __construct(Connection $connection, Processor $processor)
140
141
/**
141
142
* Set the projections.
142
143
*
143
- * @param array $columns
144
+ * @param array $columns
144
145
* @return $this
145
146
*/
146
147
public function project ($ columns )
@@ -152,8 +153,7 @@ public function project($columns)
152
153
153
154
/**
154
155
* Set the cursor timeout in seconds.
155
- *
156
- * @param int $seconds
156
+ * @param int $seconds
157
157
* @return $this
158
158
*/
159
159
public function timeout ($ seconds )
@@ -166,7 +166,7 @@ public function timeout($seconds)
166
166
/**
167
167
* Set the cursor hint.
168
168
*
169
- * @param mixed $index
169
+ * @param mixed $index
170
170
* @return $this
171
171
*/
172
172
public function hint ($ index )
@@ -217,8 +217,8 @@ public function cursor($columns = [])
217
217
/**
218
218
* Execute the query as a fresh "select" statement.
219
219
*
220
- * @param array $columns
221
- * @param bool $returnLazy
220
+ * @param array $columns
221
+ * @param bool $returnLazy
222
222
* @return array|static[]|Collection|LazyCollection
223
223
*/
224
224
public function getFresh ($ columns = [], $ returnLazy = false )
@@ -524,10 +524,10 @@ public function orderBy($column, $direction = 'asc')
524
524
/**
525
525
* Add a "where all" clause to the query.
526
526
*
527
- * @param string $column
528
- * @param array $values
529
- * @param string $boolean
530
- * @param bool $not
527
+ * @param string $column
528
+ * @param array $values
529
+ * @param string $boolean
530
+ * @param bool $not
531
531
* @return $this
532
532
*/
533
533
public function whereAll ($ column , array $ values , $ boolean = 'and ' , $ not = false )
@@ -742,8 +742,8 @@ public function truncate(): bool
742
742
/**
743
743
* Get an array with the values of a given column.
744
744
*
745
- * @param string $column
746
- * @param string $key
745
+ * @param string $column
746
+ * @param string $key
747
747
* @return array
748
748
*
749
749
* @deprecated
@@ -775,9 +775,9 @@ public function raw($expression = null)
775
775
/**
776
776
* Append one or more values to an array.
777
777
*
778
- * @param mixed $column
779
- * @param mixed $value
780
- * @param bool $unique
778
+ * @param mixed $column
779
+ * @param mixed $value
780
+ * @param bool $unique
781
781
* @return int
782
782
*/
783
783
public function push ($ column , $ value = null , $ unique = false )
@@ -802,8 +802,8 @@ public function push($column, $value = null, $unique = false)
802
802
/**
803
803
* Remove one or more values from an array.
804
804
*
805
- * @param mixed $column
806
- * @param mixed $value
805
+ * @param mixed $column
806
+ * @param mixed $value
807
807
* @return int
808
808
*/
809
809
public function pull ($ column , $ value = null )
@@ -826,7 +826,7 @@ public function pull($column, $value = null)
826
826
/**
827
827
* Remove one or more fields.
828
828
*
829
- * @param mixed $columns
829
+ * @param mixed $columns
830
830
* @return int
831
831
*/
832
832
public function drop ($ columns )
@@ -857,8 +857,8 @@ public function newQuery()
857
857
/**
858
858
* Perform an update query.
859
859
*
860
- * @param array $query
861
- * @param array $options
860
+ * @param array $query
861
+ * @param array $options
862
862
* @return int
863
863
*/
864
864
protected function performUpdate ($ query , array $ options = [])
@@ -882,7 +882,7 @@ protected function performUpdate($query, array $options = [])
882
882
/**
883
883
* Convert a key to ObjectID if needed.
884
884
*
885
- * @param mixed $id
885
+ * @param mixed $id
886
886
* @return mixed
887
887
*/
888
888
public function convertKey ($ id )
@@ -1016,7 +1016,7 @@ protected function compileWheres(): array
1016
1016
}
1017
1017
1018
1018
/**
1019
- * @param array $where
1019
+ * @param array $where
1020
1020
* @return array
1021
1021
*/
1022
1022
protected function compileWhereAll (array $ where ): array
@@ -1027,7 +1027,7 @@ protected function compileWhereAll(array $where): array
1027
1027
}
1028
1028
1029
1029
/**
1030
- * @param array $where
1030
+ * @param array $where
1031
1031
* @return array
1032
1032
*/
1033
1033
protected function compileWhereBasic (array $ where ): array
@@ -1083,7 +1083,7 @@ protected function compileWhereBasic(array $where): array
1083
1083
}
1084
1084
1085
1085
/**
1086
- * @param array $where
1086
+ * @param array $where
1087
1087
* @return mixed
1088
1088
*/
1089
1089
protected function compileWhereNested (array $ where ): mixed
@@ -1094,7 +1094,7 @@ protected function compileWhereNested(array $where): mixed
1094
1094
}
1095
1095
1096
1096
/**
1097
- * @param array $where
1097
+ * @param array $where
1098
1098
* @return array
1099
1099
*/
1100
1100
protected function compileWhereIn (array $ where ): array
@@ -1105,7 +1105,7 @@ protected function compileWhereIn(array $where): array
1105
1105
}
1106
1106
1107
1107
/**
1108
- * @param array $where
1108
+ * @param array $where
1109
1109
* @return array
1110
1110
*/
1111
1111
protected function compileWhereNotIn (array $ where ): array
@@ -1116,7 +1116,7 @@ protected function compileWhereNotIn(array $where): array
1116
1116
}
1117
1117
1118
1118
/**
1119
- * @param array $where
1119
+ * @param array $where
1120
1120
* @return array
1121
1121
*/
1122
1122
protected function compileWhereNull (array $ where ): array
@@ -1128,7 +1128,7 @@ protected function compileWhereNull(array $where): array
1128
1128
}
1129
1129
1130
1130
/**
1131
- * @param array $where
1131
+ * @param array $where
1132
1132
* @return array
1133
1133
*/
1134
1134
protected function compileWhereNotNull (array $ where ): array
@@ -1140,7 +1140,7 @@ protected function compileWhereNotNull(array $where): array
1140
1140
}
1141
1141
1142
1142
/**
1143
- * @param array $where
1143
+ * @param array $where
1144
1144
* @return array
1145
1145
*/
1146
1146
protected function compileWhereBetween (array $ where ): array
@@ -1173,63 +1173,124 @@ protected function compileWhereBetween(array $where): array
1173
1173
}
1174
1174
1175
1175
/**
1176
- * @param array $where
1176
+ * @param array $where
1177
1177
* @return array
1178
1178
*/
1179
1179
protected function compileWhereDate (array $ where ): array
1180
1180
{
1181
1181
extract ($ where );
1182
1182
1183
- $ where [ ' operator ' ] = $ operator ;
1184
- $ where [ ' value ' ] = $ value ;
1183
+ $ startOfDay = new UTCDateTime (Carbon:: parse ( $ value )-> startOfDay ()) ;
1184
+ $ endOfDay = new UTCDateTime (Carbon:: parse ( $ value)-> endOfDay ()) ;
1185
1185
1186
- return $ this ->compileWhereBasic ($ where );
1186
+ $ operator = $ this ->conversion [$ operator ];
1187
+
1188
+ return match ($ operator ) {
1189
+ '= ' => [
1190
+ $ column => [
1191
+ '$gte ' => $ startOfDay ,
1192
+ '$lte ' => $ endOfDay ,
1193
+ ],
1194
+ ],
1195
+ '$ne ' => [
1196
+ $ column => [
1197
+ '$gt ' => $ endOfDay ,
1198
+ '$lt ' => $ startOfDay ,
1199
+ ],
1200
+ ],
1201
+ '$lt ' => [
1202
+ $ column => [
1203
+ '$lt ' => $ startOfDay ,
1204
+ ],
1205
+ ],
1206
+ '$gt ' => [
1207
+ $ column => [
1208
+ '$gt ' => $ endOfDay ,
1209
+ ],
1210
+ ],
1211
+ '$lte ' => [
1212
+ $ column => [
1213
+ '$lte ' => $ endOfDay ,
1214
+ ],
1215
+ ],
1216
+ '$gte ' => [
1217
+ $ column => [
1218
+ '$gte ' => $ startOfDay ,
1219
+ ],
1220
+ ],
1221
+ };
1187
1222
}
1188
1223
1189
1224
/**
1190
- * @param array $where
1225
+ * @param array $where
1191
1226
* @return array
1192
1227
*/
1193
1228
protected function compileWhereMonth (array $ where ): array
1194
1229
{
1195
1230
extract ($ where );
1196
1231
1197
- $ where [ ' operator ' ] = $ operator ;
1198
- $ where [ ' value ' ] = $ value ;
1232
+ $ operator = $ operator === ' = ' ? ' $eq ' : $ this -> conversion [ $ operator ] ;
1233
+ $ value = str_starts_with ( $ value , ' 0 ' ) ? intval ( str_replace ( ' 0 ' , '' , $ value )) : $ value ;
1199
1234
1200
- return $ this ->compileWhereBasic ($ where );
1235
+ return [
1236
+ '$expr ' => [
1237
+ $ operator => [
1238
+ [
1239
+ '$month ' => '$ ' .$ column
1240
+ ],
1241
+ $ value ,
1242
+ ],
1243
+ ],
1244
+ ];
1201
1245
}
1202
1246
1203
1247
/**
1204
- * @param array $where
1248
+ * @param array $where
1205
1249
* @return array
1206
1250
*/
1207
1251
protected function compileWhereDay (array $ where ): array
1208
1252
{
1209
1253
extract ($ where );
1210
1254
1211
- $ where [ ' operator ' ] = $ operator ;
1212
- $ where [ ' value ' ] = $ value ;
1255
+ $ operator = $ operator === ' = ' ? ' $eq ' : $ this -> conversion [ $ operator ] ;
1256
+ $ value = str_starts_with ( $ value , ' 0 ' ) ? intval ( str_replace ( ' 0 ' , '' , $ value )) : $ value ;
1213
1257
1214
- return $ this ->compileWhereBasic ($ where );
1258
+ return [
1259
+ '$expr ' => [
1260
+ $ operator => [
1261
+ [
1262
+ '$dayOfMonth ' => '$ ' .$ column
1263
+ ],
1264
+ $ value ,
1265
+ ],
1266
+ ],
1267
+ ];
1215
1268
}
1216
1269
1217
1270
/**
1218
- * @param array $where
1271
+ * @param array $where
1219
1272
* @return array
1220
1273
*/
1221
1274
protected function compileWhereYear (array $ where ): array
1222
1275
{
1223
1276
extract ($ where );
1224
1277
1225
- $ where ['operator ' ] = $ operator ;
1226
- $ where ['value ' ] = $ value ;
1278
+ $ operator = $ operator === '= ' ? '$eq ' : $ this ->conversion [$ operator ];
1227
1279
1228
- return $ this ->compileWhereBasic ($ where );
1280
+ return [
1281
+ '$expr ' => [
1282
+ $ operator => [
1283
+ [
1284
+ '$year ' => '$ ' .$ column
1285
+ ],
1286
+ $ value
1287
+ ],
1288
+ ],
1289
+ ];
1229
1290
}
1230
1291
1231
1292
/**
1232
- * @param array $where
1293
+ * @param array $where
1233
1294
* @return array
1234
1295
*/
1235
1296
protected function compileWhereTime (array $ where ): array
@@ -1243,7 +1304,7 @@ protected function compileWhereTime(array $where): array
1243
1304
}
1244
1305
1245
1306
/**
1246
- * @param array $where
1307
+ * @param array $where
1247
1308
* @return mixed
1248
1309
*/
1249
1310
protected function compileWhereRaw (array $ where ): mixed
@@ -1254,7 +1315,7 @@ protected function compileWhereRaw(array $where): mixed
1254
1315
/**
1255
1316
* Set custom options for the query.
1256
1317
*
1257
- * @param array $options
1318
+ * @param array $options
1258
1319
* @return $this
1259
1320
*/
1260
1321
public function options (array $ options )
0 commit comments