diff --git a/README.md b/README.md index 2d6779d..af32b1a 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,6 @@ and use them in your project or submit them to be added to the library. Currently included drivers are: * [Redis](src/Driver/Redis/Redis.php) -* [Cassandra](src/Driver/Cassandra/Cassandra.php) * [Mysqli](src/Driver/Mysqli/Mysqli.php) * [OpenSearch](src/Driver/OpenSearch/OpenSearch.php) diff --git a/composer.json b/composer.json index f6d15c8..3e59d93 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,6 @@ "phpunit/phpunit": "^12.3" }, "suggest": { - "ext-cassandra": "To use the Cassandra NoSQL driver", "ext-mysqli": "To use the Mysqli Relational driver", "ext-redis": "To use the Redis Cache driver", "shyim/opensearch-php-dsl": "OpenSearch DSL query builder" diff --git a/src/Driver/Cassandra/Cassandra.php b/src/Driver/Cassandra/Cassandra.php deleted file mode 100644 index f0089d9..0000000 --- a/src/Driver/Cassandra/Cassandra.php +++ /dev/null @@ -1,285 +0,0 @@ -host = $host ?? $this->host; - $this->port = $port ?? $this->port; - $this->user = $user ?? $this->user; - $this->password = $password ?? $this->password; - $this->keyspace = $keyspace ?? $this->keyspace; - } - - /** - * Connect to cassandra database - */ - protected function connect(): void - { - if ($this->connection) { - return; - } - - $builder = \Cassandra::cluster(); - - if ($this->host) { - $builder->withContactPoints($this->host); - } - - if ($this->port) { - $builder->withPort($this->port); - } - - if ($this->user && $this->password) { - $builder->withCredentials($this->user, $this->password); - } - - $cluster = $builder->build(); - $this->connection = $cluster->connect($this->keyspace); - } - - /** - * Execute a cassandra query - * - * @param string $query - * @return Rows - * @throws CassandraModelException if an error occurs while executing the query - */ - protected function rawQuery(string $query): Rows - { - $this->connect(); - - $statement = new SimpleStatement($query); - try { - return $this->connection->execute($statement, null); - } catch (Exception $e) { - throw CassandraModelException::wrapping($e); - } - } - - /** - * Save the model - * - * @param ModelInterface $model - * @return bool - * @throws CassandraModelException if an error occurs while executing the query - */ - public function save(ModelInterface $model): bool - { - $table = $model::getName(); - - $data = json_encode($model); - $data = str_replace("'", "''", $data); - - $query = "INSERT INTO " . $table . " JSON '" . $data . "';"; - $this->rawQuery($query); - - return true; - } - - /** - * Get the model - * - * @param class-string $modelClass - * @param mixed $id - * @param ModelInterface|null $model - * @return ModelInterface|null - * @throws CassandraModelException if an error occurs while executing the query - */ - public function get(string $modelClass, mixed $id, ?ModelInterface $model = null): ?ModelInterface - { - $table = $modelClass::getName(); - - $id = str_replace("'", "''", $id); - $query = "SELECT * FROM " . $table . " WHERE " . $modelClass::getIdField() . " = '" . $id . "'"; - $rows = $this->rawQuery($query); - if ($rows->count() === 0) { - return null; - } - - $current = $rows->current(); - if ($model) { - return $model->applyData($current); - } - return $modelClass::getModelFromData($current); - } - - /** - * Delete the model - * - * @param ModelInterface $model - * @return bool - * @throws CassandraModelException if an error occurs while executing the query - */ - public function delete(ModelInterface $model): bool - { - $table = $model::getName(); - - $id = str_replace("'", "''", $model->getId()); - $query = "DELETE FROM " . $table . " WHERE " . $model->getIdField() . " = '" . $id . "'"; - $this->rawQuery($query); - return true; - } - - /** - * Execute a SELECT, UPDATE or DELETE query - * - * @param Query $query - * @return QueryResult - * @throws CassandraModelException if an error occurs while executing the query - */ - public function query(Query $query): QueryResult - { - $this->connect(); - - $generator = new SQL(function ($value) { - return str_replace("'", "''", $value); - }); - - $generator->columnEnclosure = ""; - $generator->tableEnclosure = ""; - - $queryString = $generator->generate($query); - - $rawQueryResult = $this->rawQuery($queryString); - - $result = new QueryResult(); - $result->setQueryString($queryString); - foreach ($rawQueryResult as $resultRow) { - /** @var class-string $modelClass */ - $modelClass = $query->modelClassName; - $model = $modelClass::getModelFromData($resultRow); - $result->add($model); - } - - return $result; - } - - /** - * @param string|null $host - * @return Cassandra - */ - public function setHost(?string $host): Cassandra - { - $this->host = $host; - return $this; - } - - /** - * @param int|null $port - * @return Cassandra - */ - public function setPort(?int $port): Cassandra - { - $this->port = $port; - return $this; - } - - /** - * @param string|null $user - * @return Cassandra - */ - public function setUser(?string $user): Cassandra - { - $this->user = $user; - return $this; - } - - /** - * @param string|null $password - * @return Cassandra - */ - public function setPassword(?string $password): Cassandra - { - $this->password = $password; - return $this; - } - - /** - * @param string $keyspace - * @return Cassandra - */ - public function setKeyspace(string $keyspace): Cassandra - { - $this->keyspace = $keyspace; - return $this; - } -} diff --git a/src/Driver/Cassandra/CassandraModelException.php b/src/Driver/Cassandra/CassandraModelException.php deleted file mode 100644 index caac9e6..0000000 --- a/src/Driver/Cassandra/CassandraModelException.php +++ /dev/null @@ -1,20 +0,0 @@ -getMessage(), $exception->getCode(), $exception); - } -} diff --git a/src/Driver/DriverRegistry.php b/src/Driver/DriverRegistry.php index f2fffa6..9817926 100644 --- a/src/Driver/DriverRegistry.php +++ b/src/Driver/DriverRegistry.php @@ -2,7 +2,6 @@ namespace Aternos\Model\Driver; -use Aternos\Model\Driver\Cassandra\Cassandra; use Aternos\Model\Driver\OpenSearch\OpenSearch; use Aternos\Model\Driver\Mysqli\Mysqli; use Aternos\Model\Driver\Redis\Redis; @@ -20,7 +19,6 @@ class DriverRegistry implements DriverRegistryInterface * @var array|string[] */ protected array $classes = [ - Cassandra::ID => Cassandra::class, OpenSearch::ID => OpenSearch::class, Mysqli::ID => Mysqli::class, Redis::ID => Redis::class,