Skip to content

Commit bebb231

Browse files
committed
Fix query builder
1 parent 9286329 commit bebb231

2 files changed

Lines changed: 49 additions & 13 deletions

File tree

‎src/Database/Barry/Model.php‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -890,10 +890,7 @@ public function __get(string $name): mixed
890890

891891
if (!$attribute_exists && method_exists($this, $name)) {
892892
$result = $this->$name();
893-
if ($result instanceof Relation) {
894-
return $result->getResults();
895-
}
896-
return $result;
893+
return $result instanceof Relation ? $result->getResults() : $result;
897894
}
898895

899896
if (!$attribute_exists) {
@@ -998,23 +995,27 @@ private function executeDataCasting(string $name): mixed
998995
}
999996

1000997
if ($type === "int") {
1001-
return (int)$value;
998+
return (int) $value;
1002999
}
10031000

10041001
if ($type === "float") {
1005-
return (float)$value;
1002+
return (float) $value;
10061003
}
10071004

10081005
if ($type === "double") {
1009-
return (float)$value;
1006+
return (float) $value;
1007+
}
1008+
1009+
if ($type === "boolean" || $type === "bool") {
1010+
return (bool) $value;
10101011
}
10111012

10121013
if ($type === "json") {
10131014
if (is_array($value)) {
1014-
return (object)$value;
1015+
return (object) $value;
10151016
}
10161017
if (is_object($value)) {
1017-
return (object)$value;
1018+
return (object) $value;
10181019
}
10191020
return json_decode(
10201021
$value,

‎src/Database/QueryBuilder.php‎

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,37 @@ private static function isComparisonOperator(mixed $comparator): bool
291291
}
292292

293293
return in_array(Str::upper($comparator), [
294-
'=', '>', '<', '>=', '=<', '<>', '!=', 'LIKE', 'NOT', 'IS NOT', "IN", "NOT IN",
295-
'ILIKE', '&', '|', '<<', '>>', 'NOT LIKE',
296-
'&&', '@>', '<@', '?', '?|', '?&', '||', '-', '@?', '@@', '#-',
297-
'IS DISTINCT FROM', 'IS NOT DISTINCT FROM',
294+
'=',
295+
'>',
296+
'<',
297+
'>=',
298+
'=<',
299+
'<>',
300+
'!=',
301+
'LIKE',
302+
'NOT',
303+
'IS NOT',
304+
"IN",
305+
"NOT IN",
306+
'ILIKE',
307+
'&',
308+
'|',
309+
'<<',
310+
'>>',
311+
'NOT LIKE',
312+
'&&',
313+
'@>',
314+
'<@',
315+
'?',
316+
'?|',
317+
'?&',
318+
'||',
319+
'-',
320+
'@?',
321+
'@@',
322+
'#-',
323+
'IS DISTINCT FROM',
324+
'IS NOT DISTINCT FROM',
298325
], true);
299326
}
300327

@@ -905,6 +932,10 @@ private function bind(PDOStatement $pdo_statement, array $bindings = []): void
905932
$param = PDO::PARAM_INT;
906933
} elseif (is_resource($value)) {
907934
$param = PDO::PARAM_LOB;
935+
} elseif (is_bool($value)) {
936+
$param = PDO::PARAM_BOOL;
937+
} elseif (is_string($value)) {
938+
$param = PDO::PARAM_STR;
908939
}
909940
$key_binding = is_string($key) ? ":$key" : $key + 1;
910941
$pdo_statement->bindValue($key_binding, $value, $param);
@@ -920,6 +951,10 @@ private function bind(PDOStatement $pdo_statement, array $bindings = []): void
920951
$param = PDO::PARAM_INT;
921952
} elseif (is_resource($value)) {
922953
$param = PDO::PARAM_LOB;
954+
} elseif (is_bool($value)) {
955+
$param = PDO::PARAM_BOOL;
956+
} elseif (is_string($value)) {
957+
$param = PDO::PARAM_STR;
923958
}
924959
$pdo_statement->bindValue($i, $value, $param);
925960
$i++;

0 commit comments

Comments
 (0)