Search code examples
scalacassandradatastaxphantom-dslphantom-types

How to select fields from SetColumn[String] in Phantom


I have a Cassandra table Department with columns name_list extends SetColumn[String] with PartitionKey and id extends StringColumn with PartitionKey.

I want to fetch id where the requested name is present in name_list.

I tried using this code below but not getting any results

abstract class Departments extends Table[Departments, Department] with RootConnector {

  object id extends StringColumn with PartitionKey

  object dep_type extends StringColumn

  object name_list extends SetColumn[String] with Index

      def getByName(name: String) = {
        select(_.id, _.name_list)
          .where(_.name_list.contains(name))
          .allowFiltering()
          .one()
      }
}

Is there any way to solve this!!


Solution

  • I think we do not need to extend Index for it. It is working fine with this too:-

    object name_list extends SetColumn[String]
    

    Now, I am getting id and name_list by using the same method as above:-

    def getByName(name: String) = {
        select(_.id, _.name_list)
          .where(_.name_list.contains(name))
          .allowFiltering()
          .one()
      }