diff --git a/src/Attributes/QueryBuilderQuery.php b/src/Attributes/QueryBuilderQuery.php new file mode 100644 index 0000000..bbb3fd2 --- /dev/null +++ b/src/Attributes/QueryBuilderQuery.php @@ -0,0 +1,46 @@ +getProperties(); + + foreach ($properties as $property) + { + $attributes = $property->getAttributes(); + $propertyName = $property->getName(); + $propertyValue = $property->getValue($target); + + if(sizeof($attributes) == 0) continue; + + foreach ($attributes as $attribute) + { + if($attribute->getName() == "$nameBase\\QueryBuilderRequiredField") + { + if($propertyValue == "") + throw new \Exception(); + } + + } + } + } +} diff --git a/src/Attributes/QueryBuilderRequiredField.php b/src/Attributes/QueryBuilderRequiredField.php new file mode 100644 index 0000000..35a75bc --- /dev/null +++ b/src/Attributes/QueryBuilderRequiredField.php @@ -0,0 +1,20 @@ +Required = $required; + parent::__construct(new Name("QueryBuilderRequiredField", []), [], []); + } +} diff --git a/src/Enumerators/DeegraphEqualityOperator.php b/src/Enumerators/DeegraphEqualityOperator.php new file mode 100644 index 0000000..8e1cb66 --- /dev/null +++ b/src/Enumerators/DeegraphEqualityOperator.php @@ -0,0 +1,13 @@ +"; + case LESS_THAN_OR_EQUAL_TO = "<="; + case MORE_THAN_OR_EQUAL_TO = ">="; +} + diff --git a/src/QueryBuilder/QueryBuilder.php b/src/QueryBuilder/QueryBuilder.php old mode 100644 new mode 100755 index 0bad704..adc943b --- a/src/QueryBuilder/QueryBuilder.php +++ b/src/QueryBuilder/QueryBuilder.php @@ -8,8 +8,17 @@ use Darksparrow\DeegraphPHP\QueryBuilder\QueryBuilders\Select; class QueryBuilder { + + public function Insert(): Insert + { + return new Insert(); + } public function Put(): Put { return new Put(); } + public function Select(): Select + { + return new Select(); + } } diff --git a/src/QueryBuilder/QueryBuilders/Insert.php b/src/QueryBuilder/QueryBuilders/Insert.php new file mode 100755 index 0000000..3d3c98b --- /dev/null +++ b/src/QueryBuilder/QueryBuilders/Insert.php @@ -0,0 +1,83 @@ +ValidateValues($this); + + $builder = "INSERT INTO $this->RelativePath"; + + if(sizeof($this->Keys) > 0) $builder .= "KEYS " . implode(separator: ", ", array: $this->Keys); + if(sizeof($this->Schemas) > 0) $builder .= "SCHEMAS " . implode(separator: ", ", array: $this->Schemas); + if($this->Values != "") $builder .= "VALUES $this->Values"; + if($this->Duplicate) $builder .= "DUPLICATE"; + if($this->Replace) $builder .= "REPLACE"; + + return $builder; + } + + public function RelativePath(string $relativePath): Insert + { + $this->RelativePath = $relativePath; + return $this; + } + + public function Keys(string $keys): Insert + { + $this->Keys = $keys; + return $this; + } + + public function Schemas(string $schemas): Insert + { + $this->Schemas = $schemas; + return $this; + } + + public function Values(string $values): Insert + { + $this->Values .= $values; + return $this; + } + + public function Duplicate(): Insert + { + $this->Duplicate = true; + return $this; + } + + public function Replace(): Insert + { + $this->Replace = true; + return $this; + } +} \ No newline at end of file diff --git a/src/QueryBuilder/QueryBuilders/Select.php b/src/QueryBuilder/QueryBuilders/Select.php new file mode 100755 index 0000000..650a159 --- /dev/null +++ b/src/QueryBuilder/QueryBuilders/Select.php @@ -0,0 +1,51 @@ +RelativePaths)) $builder .= " " . implode(separator: ", ", array: $this->RelativePaths); + if($this->From != "") $builder .= " FROM $this->From"; + if($this->Where != "") $builder .= " WHERE $this->Where"; + if($this->InstanceOf != "") $builder .= " INSTANCEOF $this->InstanceOf"; + + return $builder; + } + + public function RelativePaths(array $relativePaths): Select + { + $this->RelativePaths = $relativePaths; + return $this; + } + public function Where(string $target, DeegraphEqualityOperator $operator, string $value): Select + { + $this->Where = "" . $target . " " . $operator->value . " " . $value; + return $this; + } +} \ No newline at end of file