【问题标题】:Convenient way of inserting values to Cassandra with Phantom使用 Phantom 向 Cassandra 插入值的便捷方式
【发布时间】:2015-08-07 23:02:19
【问题描述】:

有人知道通过 phatom-dsl 向 Cassandra 插入值的便捷方法吗?目前我正在这样做:

case class Entry(id: UUID, firstName: String, lastName: String)

sealed class EntryTable extends CassandraTable[EntryTable, Entry] {
  override val tableName = "entries"
  object id extends UUIDColumn(this) with Index[UUID]
  object firstName extends StringColumn(this)
  object lastName extends StringColumn(this)

  override def fromRow(r: dsl.Row): Entry = {
    Entry(id(r), firstName(r), firstName(r))
  }
}

object EntryTable extends EntryTable {
   private val connector = CassandraConnector.apply(Set(InetAddress.getByName("localhost")))
   implicit val keySpace = KeySpace("keyspace")

   def insert(e: Entry) = {
     connector.withSessionDo(implicit session => {
       insert().value(_.id, e.id)).value(_.firstName, e.firstName).value(_.lastName, e.lastName).future()
     }
   }
}

但我想做:

def insert(e: Entry) = {
  connector.withSessionDo(implicit session => {
    insert().value(e).future()
  }
}

当案例类有很多字段时,这会更方便。有什么想法吗?

【问题讨论】:

    标签: scala phantom-dsl


    【解决方案1】:

    您使用 API 略有错误,我们正在发布多个教程以公开“新”方式。同时,它的基本版本可用here 和激活器模板中的this branch 也描述了您需要了解的所有内容。

    具体插入记录的方式描述here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-18
      • 2017-08-27
      • 1970-01-01
      • 2016-09-19
      • 2016-09-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-05
      相关资源
      最近更新 更多