Derive mode from DSN function

- Add headers in all files
- Minor field name changes
This commit is contained in:
2024-07-20 21:47:21 -04:00
parent 1a37b009ea
commit d8330d828a
81 changed files with 1053 additions and 551 deletions

View File

@@ -1,7 +1,15 @@
<?php declare(strict_types=1);
<?php
/**
* @author Daniel J. Summers <daniel@bitbadger.solutions>
* @license MIT
*/
declare(strict_types=1);
namespace BitBadger\PDODocument;
use Exception;
/**
* Criteria for a field WHERE clause
*/
@@ -48,19 +56,19 @@ class Field
* Get the WHERE clause fragment for this parameter
*
* @return string The WHERE clause fragment for this parameter
* @throws DocumentException If the database mode has not been set
* @throws Exception|DocumentException If the database mode has not been set
*/
public function toWhere(): string
{
$fieldName = ($this->qualifier == '' ? '' : "$this->qualifier.") . 'data' . match (true) {
$mode = Configuration::mode('make field WHERE clause');
$fieldName = (empty($this->qualifier) ? '' : "$this->qualifier.") . 'data' . match (true) {
!str_contains($this->fieldName, '.') => "->>'$this->fieldName'",
Configuration::$mode == Mode::PgSQL => "#>>'{" . implode(',', explode('.', $this->fieldName)) . "}'",
Configuration::$mode == Mode::SQLite => "->>'" . implode("'->>'", explode('.', $this->fieldName)) . "'",
default => throw new DocumentException('Database mode not set; cannot make field WHERE clause')
$mode === Mode::PgSQL => "#>>'{" . implode(',', explode('.', $this->fieldName)) . "}'",
$mode === Mode::SQLite => "->>'" . implode("'->>'", explode('.', $this->fieldName)) . "'"
};
$fieldPath = match (Configuration::$mode) {
$fieldPath = match ($mode) {
Mode::PgSQL => match (true) {
$this->op == Op::BT => is_numeric($this->value[0]) ? "($fieldName)::numeric" : $fieldName,
$this->op === Op::BT => is_numeric($this->value[0]) ? "($fieldName)::numeric" : $fieldName,
is_numeric($this->value) => "($fieldName)::numeric",
default => $fieldName
},
@@ -71,7 +79,7 @@ class Field
Op::BT => " {$this->paramName}min AND {$this->paramName}max",
default => " $this->paramName"
};
return $fieldPath . ' ' . $this->op->toString() . $criteria;
return $fieldPath . ' ' . $this->op->toSQL() . $criteria;
}
/**