Skip to content

Collection operators

Flavian Alexandru edited this page May 30, 2016 · 6 revisions

Build Status Coverage Status Maven Central Bintray

back to top

Based on the above list of columns, phantom supports CQL 3 modify operations for CQL 3 collections: list, set, map. All operators will be available in an update query, specifically:

db.table.update
  .where(_.id eqs someId)
  .modify(_.someList $OPERATOR $args)
  .future()

Examples in ListOperatorsTest.scala.

Name Description
prepend Adds an item to the head of the list
prependAll Adds multiple items to the head of the list
append Adds an item to the tail of the list
appendAll Adds multiple items to the tail of the list
discard Removes the given item from the list.
discardAll Removes all given items from the list.
setIdIx Updates a specific index in the list

Sets have a better performance than lists, as the Cassandra documentation suggests. Examples in SetOperationsTest.scala.

Name Description
add Adds an item to the tail of the set
addAll Adds multiple items to the tail of the set
remove Removes the given item from the set.
removeAll Removes all given items from the set.

Both the key and value types of a Map must be Cassandra primitives. Examples in MapOperationsTest.scala:

Name Description
put Adds an (key -> value) pair to the map
putAll Adds multiple (key -> value) pairs to the map
setTo Updates the value of a key in map, with Database.table.update.where(_.id eqs id).modify(_.map(key) setTo value).future()