aboutsummaryrefslogtreecommitdiffhomepage
path: root/services/app/src/Sql/Internal/Update.php
diff options
context:
space:
mode:
Diffstat (limited to 'services/app/src/Sql/Internal/Update.php')
-rw-r--r--services/app/src/Sql/Internal/Update.php78
1 files changed, 78 insertions, 0 deletions
diff --git a/services/app/src/Sql/Internal/Update.php b/services/app/src/Sql/Internal/Update.php
new file mode 100644
index 0000000..a9e9816
--- /dev/null
+++ b/services/app/src/Sql/Internal/Update.php
@@ -0,0 +1,78 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Nsfisis\Albatross\Sql\Internal;
+
+use Nsfisis\Albatross\Exceptions\InvalidSqlException;
+use Nsfisis\Albatross\Sql\QueryBuilder;
+
+final class Update
+{
+ /**
+ * @var ?array<string, string|int>
+ */
+ private ?array $set;
+
+ private string $where = '';
+
+ /**
+ * @internal
+ */
+ public function __construct(
+ private readonly QueryBuilder $sql,
+ private readonly string $table,
+ ) {
+ }
+
+ /**
+ * @param array<string, string|int> $set
+ */
+ public function set(array $set): self
+ {
+ $this->set = $set;
+ return $this;
+ }
+
+ public function where(string $where): self
+ {
+ $this->where = $where;
+ return $this;
+ }
+
+ /**
+ * @param array<string, string|int> $params
+ */
+ public function execute(array $params = []): void
+ {
+ $this->sql->_executeUpdate($this, $params);
+ }
+
+ /**
+ * @internal
+ */
+ public function _getTable(): string
+ {
+ return $this->table;
+ }
+
+ /**
+ * @internal
+ */
+ public function _getWhere(): string
+ {
+ return $this->where;
+ }
+
+ /**
+ * @internal
+ * @return array<string, string|int>
+ */
+ public function _getSet(): array
+ {
+ if (!isset($this->set)) {
+ throw new InvalidSqlException('UPDATE: $set must be set before calling execute()');
+ }
+ return $this->set;
+ }
+}