使用 Phantom DSL 为 Cassandra 创建模型
Creating Model for Cassandra using Phantom DSL
我正在阅读this piece of source code。
这看起来不错,但如果该字段不是艺术家,而是 "artists",其中艺术家是 cassandra 中的 list<text>
怎么办?
我找到了这篇关于使用 ListColumn 的文章
https://github.com/websudos/phantom/wiki/Collection-columns
但我不确定您将如何在 ListColumn 上定义索引
object genre extends ListColumn(this) with Index[List[String]]
上面的行不编译。
据我所知,您只能在 Set 列上执行包含二级索引的查询,而不能在 List 上执行。
这是您的操作:object genre extends SetColumn[Table, Record, Int](this) with Index[Set[Int]]
。 Table
和 Record
这两种类型必须与您在上面扩展 CassandraTable
时提供的内容相匹配,如下所示:
class MyTable extends CassandraTable[MyTable, MyRecord] {
object genre extends SetColumn[MyTable, MyRecord, Int](this) with Index[Set[Int]]
}
希望这是有道理的。也要小心 ListColumn
,所有集合列都需要 TableType
和 RecordType
参数。
更新
在较新版本的 phantom 中,您不需要提供 table 的类型和记录。只需执行以下操作:
class MyTable extends CassandraTable[MyTable, MyRecord] {
object genre extends SetColumn[Int](this) with Index[Set[Int]]
}
有关如何定义此类 table 的示例,请参阅 this test for examples on using indexed collections, and then at this table。
此致。
我正在阅读this piece of source code。
这看起来不错,但如果该字段不是艺术家,而是 "artists",其中艺术家是 cassandra 中的 list<text>
怎么办?
我找到了这篇关于使用 ListColumn 的文章
https://github.com/websudos/phantom/wiki/Collection-columns
但我不确定您将如何在 ListColumn 上定义索引
object genre extends ListColumn(this) with Index[List[String]]
上面的行不编译。
据我所知,您只能在 Set 列上执行包含二级索引的查询,而不能在 List 上执行。
这是您的操作:object genre extends SetColumn[Table, Record, Int](this) with Index[Set[Int]]
。 Table
和 Record
这两种类型必须与您在上面扩展 CassandraTable
时提供的内容相匹配,如下所示:
class MyTable extends CassandraTable[MyTable, MyRecord] {
object genre extends SetColumn[MyTable, MyRecord, Int](this) with Index[Set[Int]]
}
希望这是有道理的。也要小心 ListColumn
,所有集合列都需要 TableType
和 RecordType
参数。
更新
在较新版本的 phantom 中,您不需要提供 table 的类型和记录。只需执行以下操作:
class MyTable extends CassandraTable[MyTable, MyRecord] {
object genre extends SetColumn[Int](this) with Index[Set[Int]]
}
有关如何定义此类 table 的示例,请参阅 this test for examples on using indexed collections, and then at this table。
此致。