I'm trying to insert some data into my database using Slick. I've successfully been able to query the database, but can't quite understand how to insert data using the documentation examples.
I've gotten to the point where all that's supposedly wrong is that my action
isn't of the correct type and it throws the error
type mismatch;
found : slick.dbio.DBIOAction[Unit,slick.dbio.NoStream,slick.dbio.Effect.Write with slick.dbio.Effect.Schema]
required: slick.dbio.DBIOAction[com.ojolabs.customer.avro.CustomerEvent,slick.dbio.NoStream,Nothing]
db.run(action)
I'm not quite certain how to return the types that are specified as required, using the code I've already written.
I'm calling my schema from here:
trait CustomerEventsComponent {
def customEventsManager: CustomerEvents.Async
}
trait DefaultCustomerEvents extends CustomerEventsComponent{
self: DatabaseComponent with ExecutionContextComponent =>
lazy val customEventsManager = new Async {
override def create(phoneNumber: String, createdAt: DateTime): Future[CustomerEvent] = {
val action = Schema.CustomerEvents.userAction
//this is the line that throws the error
db.run(action)
}
}
}
And am creating the action in here
object Schema {
class CustomerEvents(tag: Tag) extends Table[CustomerEvent](tag, "customer_events") {
def id: Rep[UUID] = column[UUID]("id", O.PrimaryKey)
def customerId: Rep[UUID] = column[UUID]("customer_id")
def eventType: Rep[String] = column[String]("type")
def createdAt: Rep[DateTime] = column[DateTime]("created_at")
def version: Rep[Double] = column[Double]("version")
def data: Rep[JsValue] = column[JsValue]("data")
def metadata: Rep[JsValue] = column[JsValue]("metadata")
def * = (id, customerId, eventType, createdAt, version, data, metadata) <> (CustomerEvent.tupled, CustomerEvent.unapply)
}
object CustomerEvents {
val all = TableQuery[CustomerEvents]
val userAction = DBIO.seq(
all.schema.create,
all += CustomerEvent(
UUID.randomUUID(),
UUID.randomUUID(),
"hello",
DateTime.now(),
1.0,
Json.toJson("{\"hello\" : \"its me\"}"),
Json.toJson("{\"hello\" : \"its me\"}"))
)
}