简体   繁体   中英

Scala Phantom Cassandra Conditional insert?

I am using Phantom library to insert rows from my Scala code into Cassandra.

So basically I create a class which extends the CassandraTable and then I get all the create, update methods from the phantom library.

One thing I want to know is how does it generate its INSERT statements. Does it generate a vanilla INSERT statement of a conditional update statement like INSERT IF NOT EXISTS.

Just log the query and the response would be obvious. By default the insert query does NOT contain ifNotExists . As of Phantom 2.5.0, tables auto-generate a store method so you can call:

database.table.store(record).ifNotExists.future()

Before phantom 2.5.0:

def store(record: Record): InsertQuery.Default[Table, Record] = {
  insert.value(_.column1, record.value1)
    .value(_.column2, record.value2)
    ...
    .ifNotExists()
}

On a side note, all queries in phantom have a .qb.queryString accessor on them so it's pretty trivial to look inside.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM