Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of github.com:kallaspriit/Cassandra-PHP-Client-…

…Library
  • Loading branch information...
commit b8485b8171044da6ff5a34c0633fc2ccdf6a20dd 2 parents 70e94ca + bc1eddf
@kallaspriit authored
Showing with 83 additions and 2 deletions.
  1. +4 −0 Cassandra.php
  2. +79 −2 CassandraModel.php
View
4 Cassandra.php
@@ -2813,6 +2813,10 @@ public function createColumnsOrSuperColumns(
$results = array();
foreach ($columns as $columnName => $columnValue) {
+ if (!isset($columnValue)) {
+ continue;
+ }
+
$column = new cassandra_ColumnOrSuperColumn();
if (is_array($columnValue)) {
View
81 CassandraModel.php
@@ -210,7 +210,15 @@ public static function load(
if (empty($columns)) {
$columns = null;
}
-
+
+ $supercolumn = null;
+ $dotPos = mb_strpos($rowKey, '.');
+
+ if ($dotPos !== false) {
+ $supercolumn = mb_substr($rowKey, $dotPos + 1);
+ $rowKey = mb_substr($rowKey, 0, $dotPos);
+ }
+
$data = $connection->cf($columnFamily)->get(
$rowKey,
$columns,
@@ -218,7 +226,7 @@ public static function load(
null,
false,
100,
- null,
+ $supercolumn,
$consistency
);
@@ -274,6 +282,23 @@ public static function getKeyRange(
100
);
}
+
+ /**
+ * Returns all columns for given row key.
+ *
+ * @param string $rowKey Row key to get data from
+ * @param Cassandra $connection If not set, the default connection is used
+ * @return array
+ */
+ public static function getAll($rowKey, Cassandra $connection = null) {
+ if (!isset($connection)) {
+ $connection = self::$_defaultConnection;
+ }
+
+ $columnFamily = self::getColumnFamilyName();
+
+ return $connection->cf($columnFamily)->getAll($rowKey);
+ }
/**
* Returns a range of columns for a key.
@@ -398,6 +423,32 @@ public static function remove(
}
/**
+ * Removes a supercolumn entry or some columns of it.
+ *
+ * If the columns is left to null, the entire row is deleted.
+ *
+ * If you already have an instance of the model, use deleteSuper().
+ *
+ * @param string $key Row key to delete
+ * @param string $supercolumn Supercolumn name
+ * @param array $columns Optional columns to delete
+ * @param integer $consistency Option override of default consistency level
+ * @param Cassandra $connection If not set, the default connection is used
+ * @return boolean Was removing the entry successful
+ */
+ public static function removeSuper(
+ $key,
+ $supercolumn,
+ array $columns = null,
+ $consistency = null,
+ Cassandra $connection = null
+ ) {
+ $model = self::getInstance($key, $connection);
+
+ return $model->deleteSuper($supercolumn, $columns, $consistency);
+ }
+
+ /**
* Removes an entry or some columns of it.
*
* If the columns is left to null, the entire row is deleted.
@@ -424,6 +475,32 @@ public function delete(array $columns = null, $consistency = null) {
}
/**
+ * Removes an supercolumn entry or some columns of it.
+ *
+ * If the columns is left to null, the entire row is deleted.
+ *
+ * Uses the currently set row key, you can change it with key() method.
+ *
+ * You can remove a row by calling removeSuper() statically.
+ *
+ * @param array $columns Optional columns to delete
+ * @param integer $consistency Option override of default consistency level
+ * @return boolean Was removing the entry successful
+ */
+ public function deleteSuper($supercolumn, array $columns = null, $consistency = null) {
+ $columnFamily = self::getColumnFamilyName();
+
+ $this->_connection->cf($columnFamily)->remove(
+ $this->_key,
+ $columns,
+ $supercolumn,
+ $consistency
+ );
+
+ return true;
+ }
+
+ /**
* Returns the column family name that corresponds to given model class.
*
* The transformation is done in following steps:

0 comments on commit b8485b8

Please sign in to comment.
Something went wrong with that request. Please try again.