Insert

Use case classes to model the data to insert

scala> case class Insertable(s: String, i: Int, l: Long) // same as the table
defined class Insertable

scala> val insertStatement = sSession.insert("mytable", Insertable("some str", 1234, 5678L))
insertStatement: com.weather.scalacass.scsession.SCInsertStatement = SCInsertStatement(INSERT INTO mykeyspace.mytable (s, i, l) VALUES (some str, 1234, 5678))

scala> insertStatement.execute()
res2: com.weather.scalacass.Result[com.datastax.driver.core.ResultSet] = Right(ResultSet[ exhausted: true, Columns[]])

If Statement

You can also specify existence of the row:

scala> val ifNotExistsInsert = insertStatement.ifNotExists
ifNotExistsInsert: com.weather.scalacass.scsession.SCInsertStatement = SCInsertStatement(INSERT INTO mykeyspace.mytable (s, i, l) VALUES (some str, 1234, 5678) IF NOT EXISTS)

scala> ifNotExistsInsert.execute()
res3: com.weather.scalacass.Result[com.datastax.driver.core.ResultSet] = Right(ResultSet[ exhausted: false, Columns[[applied](boolean), s(varchar), i(int), l(bigint)]])

Or remove the existence check:

scala> val noIfNotExistsInsert = ifNotExistsInsert.noConditional
noIfNotExistsInsert: com.weather.scalacass.scsession.SCInsertStatement = SCInsertStatement(INSERT INTO mykeyspace.mytable (s, i, l) VALUES (some str, 1234, 5678))

scala> noIfNotExistsInsert.execute()
res4: com.weather.scalacass.Result[com.datastax.driver.core.ResultSet] = Right(ResultSet[ exhausted: true, Columns[]])

TTL

You can add a TTL:

scala> val ttlInsert = insertStatement.usingTTL(12345)
ttlInsert: com.weather.scalacass.scsession.SCInsertStatement = SCInsertStatement(INSERT INTO mykeyspace.mytable (s, i, l) VALUES (some str, 1234, 5678) USING TTL 12345)

scala> ttlInsert.execute()
res5: com.weather.scalacass.Result[com.datastax.driver.core.ResultSet] = Right(ResultSet[ exhausted: true, Columns[]])

And remove the TTL:

scala> val noTtlInsert = ttlInsert.noTTL
noTtlInsert: com.weather.scalacass.scsession.SCInsertStatement = SCInsertStatement(INSERT INTO mykeyspace.mytable (s, i, l) VALUES (some str, 1234, 5678))

scala> noTtlInsert.execute()
res6: com.weather.scalacass.Result[com.datastax.driver.core.ResultSet] = Right(ResultSet[ exhausted: true, Columns[]])

Timestamp

You can specify a timestamp:

scala> val timestampInsert = insertStatement.usingTimestamp(System.currentTimeMillis)
timestampInsert: com.weather.scalacass.scsession.SCInsertStatement = SCInsertStatement(INSERT INTO mykeyspace.mytable (s, i, l) VALUES (some str, 1234, 5678) USING TIMESTAMP 1532319112197)

scala> timestampInsert.execute()
res7: com.weather.scalacass.Result[com.datastax.driver.core.ResultSet] = Right(ResultSet[ exhausted: true, Columns[]])

Or use shorthand for current time:

scala> val timestampNowInsert = insertStatement.usingTimestampNow
timestampNowInsert: com.weather.scalacass.scsession.SCInsertStatement = SCInsertStatement(INSERT INTO mykeyspace.mytable (s, i, l) VALUES (some str, 1234, 5678) USING TIMESTAMP 1532319112417)

scala> timestampNowInsert.execute()
res8: com.weather.scalacass.Result[com.datastax.driver.core.ResultSet] = Right(ResultSet[ exhausted: true, Columns[]])

And finally, remove a timestamp from the statement:

scala> val noTimestampInsert = timestampInsert.noTimestamp
noTimestampInsert: com.weather.scalacass.scsession.SCInsertStatement = SCInsertStatement(INSERT INTO mykeyspace.mytable (s, i, l) VALUES (some str, 1234, 5678))

scala> noTimestampInsert.execute()
res9: com.weather.scalacass.Result[com.datastax.driver.core.ResultSet] = Right(ResultSet[ exhausted: true, Columns[]])