我是alpakka cassandra的新手,我想在我的应用程序中编写一个简单的insert-bind查询。目前我使用的代码如下:`
val place = Place("ny", LocalDateTime.now(), "hi")
val source = Source.single(place)
val statementBinder: (Place, PreparedStatement) => BoundStatement =
(elemToInsert, preparedStatement) => preparedStatement.bind(elemToInsert.dateTime, elemToInsert.city, elemToInsert.name)
val written = source
.via(
CassandraFlow.create(CassandraWriteSettings.defaults,
"INSERT INTO test_app.places(date_available, city, name) VALUES (?, ?, ?)",
statementBinder)
)
.runWith(Sink.ignore)
我知道问题出在源代码方法上。因为当我把第二行改成:
val source = Source(1 until 3).map{_ => place}` 它可以工作,但现在我在表中插入了两行。如何使用alpakka cassandra只插入一行?
暂无答案!
目前还没有任何答案,快来回答吧!