From d544274bd6cb3405f8ab2cae5cce80d9cb51778d Mon Sep 17 00:00:00 2001 From: Cerys Lewis Date: Wed, 8 May 2024 12:35:06 +0100 Subject: [PATCH] just committing an untested Query Builder to show an example --- ...ConflictingFieldAlreadyExistsException.php | 17 +++ .../QueryBuilderInvalidInputException.php | 17 +++ ...yBuilderRequiredFieldIsNotSetException.php | 17 +++ src/QueryBuilder/QueryBuilder.php | 15 +++ src/QueryBuilder/QueryBuilderTrait.php | 23 ++++ src/QueryBuilder/QueryBuilders/Put.php | 113 ++++++++++++++++++ 6 files changed, 202 insertions(+) create mode 100644 src/Exceptions/QueryBuilderConflictingFieldAlreadyExistsException.php create mode 100755 src/Exceptions/QueryBuilderInvalidInputException.php create mode 100644 src/Exceptions/QueryBuilderRequiredFieldIsNotSetException.php create mode 100644 src/QueryBuilder/QueryBuilder.php create mode 100755 src/QueryBuilder/QueryBuilderTrait.php create mode 100755 src/QueryBuilder/QueryBuilders/Put.php diff --git a/src/Exceptions/QueryBuilderConflictingFieldAlreadyExistsException.php b/src/Exceptions/QueryBuilderConflictingFieldAlreadyExistsException.php new file mode 100644 index 0000000..62b088b --- /dev/null +++ b/src/Exceptions/QueryBuilderConflictingFieldAlreadyExistsException.php @@ -0,0 +1,17 @@ +message = "$message"; + $this->code = $code; + } +} diff --git a/src/Exceptions/QueryBuilderInvalidInputException.php b/src/Exceptions/QueryBuilderInvalidInputException.php new file mode 100755 index 0000000..1388f55 --- /dev/null +++ b/src/Exceptions/QueryBuilderInvalidInputException.php @@ -0,0 +1,17 @@ +message = "$message"; + $this->code = $code; + } +} diff --git a/src/Exceptions/QueryBuilderRequiredFieldIsNotSetException.php b/src/Exceptions/QueryBuilderRequiredFieldIsNotSetException.php new file mode 100644 index 0000000..d602249 --- /dev/null +++ b/src/Exceptions/QueryBuilderRequiredFieldIsNotSetException.php @@ -0,0 +1,17 @@ +message = "$message"; + $this->code = $code; + } +} diff --git a/src/QueryBuilder/QueryBuilder.php b/src/QueryBuilder/QueryBuilder.php new file mode 100644 index 0000000..0bad704 --- /dev/null +++ b/src/QueryBuilder/QueryBuilder.php @@ -0,0 +1,15 @@ +PutWhat != "") $builder .= " $this->PutWhat"; + + if($this->PutAt != "") $builder .= " $this->PutAt"; + elseif ($this->PutInto != "") $builder .= " $this->PutInto"; + else throw new QueryBuilderRequiredFieldIsNotSetException(); + + if($this->Safe) $builder .= " SAFE"; + return $builder; + } + + + /** + * @throws QueryBuilderInvalidInputException + */ + public function Schema(string $uri): Put + { + $this->PutWhat = self::Validate( + target: "SCHEMA \"$uri\"", + pattern: "/SCHEMA \".+\"/" + ); + return $this; + } + + /** + * @throws QueryBuilderInvalidInputException + */ + public function URI(string $uri): Put + { + $this->PutWhat = self::Validate( + target: "URI \"$uri\"", + pattern: "/URI \".+\"/" + ); + return $this; + } + + /** + * @throws QueryBuilderInvalidInputException + */ + public function DataURI(string $mimeType, string $data): Put + { + $this->PutWhat = self::Validate( + target: "URI \"data:$mimeType;$data\"", + pattern: "/URI \"data:[a-zA-Z0-9]/[a-zA-Z0-9];.+\"/" + ); + return $this; + } + + + /** + * @throws QueryBuilderInvalidInputException + * @throws QueryBuilderConflictingFieldAlreadyExistsException + */ + public function At(string $node, string $uwu): Put + { + self::EnsureNotSet($this->PutInto); + $this->PutAt = self::Validate( + target: 'AT {' . $node . '}/' . $uwu, + pattern: "/AT {[a-zA-Z0-9\-]+}\/[a-zA-Z0-9]+/" + ); + return $this; + } + + + /** + * @throws QueryBuilderInvalidInputException + * @throws QueryBuilderConflictingFieldAlreadyExistsException + */ + public function Into(string $relativePath, string $propertyName): Put + { + self::EnsureNotSet($this->PutAt); + $this->PutInto = self::Validate( + target: "INTO \"$relativePath\" AS \"$propertyName\"", + pattern: "/INTO \"[a-zA-Z0-9\-]+\" AS \"[a-zA-Z0-9]+\"/" + ); + return $this; + } + + + public function Safe(): Put + { + $this->Safe = true; + return $this; + } +}