Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions src/Database/Barry/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -890,10 +890,7 @@ public function __get(string $name): mixed

if (!$attribute_exists && method_exists($this, $name)) {
$result = $this->$name();
if ($result instanceof Relation) {
return $result->getResults();
}
return $result;
return $result instanceof Relation ? $result->getResults() : $result;
}

if (!$attribute_exists) {
Expand Down Expand Up @@ -998,23 +995,27 @@ private function executeDataCasting(string $name): mixed
}

if ($type === "int") {
return (int)$value;
return (int) $value;
}

if ($type === "float") {
return (float)$value;
return (float) $value;
}

if ($type === "double") {
return (float)$value;
return (float) $value;
}

if ($type === "boolean" || $type === "bool") {
return (bool) $value;
}

if ($type === "json") {
if (is_array($value)) {
return (object)$value;
return (object) $value;
}
if (is_object($value)) {
return (object)$value;
return (object) $value;
}
return json_decode(
$value,
Expand Down
43 changes: 39 additions & 4 deletions src/Database/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,37 @@ private static function isComparisonOperator(mixed $comparator): bool
}

return in_array(Str::upper($comparator), [
'=', '>', '<', '>=', '=<', '<>', '!=', 'LIKE', 'NOT', 'IS NOT', "IN", "NOT IN",
'ILIKE', '&', '|', '<<', '>>', 'NOT LIKE',
'&&', '@>', '<@', '?', '?|', '?&', '||', '-', '@?', '@@', '#-',
'IS DISTINCT FROM', 'IS NOT DISTINCT FROM',
'=',
'>',
'<',
'>=',
'=<',
'<>',
'!=',
'LIKE',
'NOT',
'IS NOT',
"IN",
"NOT IN",
'ILIKE',
'&',
'|',
'<<',
'>>',
'NOT LIKE',
'&&',
'@>',
'<@',
'?',
'?|',
'?&',
'||',
'-',
'@?',
'@@',
'#-',
'IS DISTINCT FROM',
'IS NOT DISTINCT FROM',
], true);
}

Expand Down Expand Up @@ -905,6 +932,10 @@ private function bind(PDOStatement $pdo_statement, array $bindings = []): void
$param = PDO::PARAM_INT;
} elseif (is_resource($value)) {
$param = PDO::PARAM_LOB;
} elseif (is_bool($value)) {
$param = PDO::PARAM_BOOL;
} elseif (is_string($value)) {
$param = PDO::PARAM_STR;
}
$key_binding = is_string($key) ? ":$key" : $key + 1;
$pdo_statement->bindValue($key_binding, $value, $param);
Expand All @@ -920,6 +951,10 @@ private function bind(PDOStatement $pdo_statement, array $bindings = []): void
$param = PDO::PARAM_INT;
} elseif (is_resource($value)) {
$param = PDO::PARAM_LOB;
} elseif (is_bool($value)) {
$param = PDO::PARAM_BOOL;
} elseif (is_string($value)) {
$param = PDO::PARAM_STR;
}
$pdo_statement->bindValue($i, $value, $param);
$i++;
Expand Down
Loading