I'm trying to simple insert an element into a databse without having an autoinc flag on the table.
Here is the table definition, I have all of the appropriate mappers defined:
class BlockHeaderTable(tag: Tag) extends Table[BlockHeader](tag,"block_headers") {
def hash = column[DoubleSha256Digest]("hash", O.PrimaryKey)
def version = column[UInt32]("version")
def previousBlockHash = column[DoubleSha256Digest]("previous_block_hash")
def merkleRootHash = column[DoubleSha256Digest]("merkle_root_hash")
def time = column[UInt32]("time")
def nBits = column[UInt32]("n_bits")
def nonce = column[UInt32]("nonce")
def * = (hash, version, previousBlockHash, merkleRootHash, time, nBits, nonce).<>[BlockHeader,
(DoubleSha256Digest, UInt32, DoubleSha256Digest, DoubleSha256Digest, UInt32, UInt32, UInt32)](blockHeaderApply,blockHeaderUnapply)
}
I'm trying to create a simple insert function for this table. Here is my attempt:
override val table = TableQuery[BlockHeaderTable]
def create(blockHeader: BlockHeader): Future[BlockHeader] = {
val insertAction = table += blockHeader
database.run(insertAction)
}
and I'm getting this error for the types:
chris@chris-870Z5E-880Z5E-680Z5E:~/dev/bitcoins-spv-node$ sbt compile
[info] Loading project definition from /home/chris/dev/bitcoins-spv-node/project
[info] Set current project to bitcoins-spv-node (in build file:/home/chris/dev/bitcoins-spv-node/)
[info] Compiling 1 Scala source to /home/chris/dev/bitcoins-spv-node/target/scala-2.11/classes...
[error] /home/chris/dev/bitcoins-spv-node/src/main/scala/org/bitcoins/spvnode/models/BlockHeaderDAO.scala:30: type mismatch;
[error] found : slick.profile.FixedSqlAction[Boolean,slick.dbio.NoStream,slick.dbio.Effect.Write]
[error] required: slick.dbio.DBIOAction[org.bitcoins.core.protocol.blockchain.BlockHeader,slick.dbio.NoStream,Nothing]
[error] database.run(insertAction)
[error] ^
[error] one error found
[error] (compile:compileIncremental) Compilation failed
[error] Total time: 3 s, completed Sep 8, 2016 2:11:32 PM
DBIOAction? - Nathaniel Fordtableis just aTableQueryobject,blockHeaderis an instance of an object thattablestores. The+=is defined inside ofSimpleInsertActionComposer- Chris StewartDBIO.seq, every test case they have using it uses that function: github.com/slick/slick/blob/… - Chris Stewarttable += blockHeaderto(table += blockHeader).andThen(DBIO.successful(blockHeader))if you want to return the just inserted object. - RomanFuture[BlockHeader]-- there has to be a better way to do this - Chris Stewart