Home > Back-end >  Scala Slick: Type Mismatch "String vs Tables.Row" during insert
Scala Slick: Type Mismatch "String vs Tables.Row" during insert

Time:09-29

Schema was generated automatically from PostgreSQl-database:

class Geopointtable(_tableTag: Tag) extends profile.api.Table[GeopointtableRow](_tableTag, "geopointtable") {
   def * = (id, latitude, longitude, date, time) <> (GeopointtableRow.tupled, GeopointtableRow.unapply)

   def ? = ((Rep.Some(id), Rep.Some(latitude), Rep.Some(longitude), Rep.Some(date), Rep.Some(time))).shaped.<>({r=>import r._; _1.map(_=> GeopointtableRow.tupled((_1.get, _2.get, _3.get, _4.get, _5.get)))}, (_:Any) =>  throw new Exception("Inserting into ? projection not supported."))

   val id: Rep[Int] = column[Int]("id", O.AutoInc, O.PrimaryKey)
   val latitude: Rep[Int] = column[Int]("latitude")
   val longitude: Rep[Int] = column[Int]("longitude")
   val date: Rep[java.sql.Date] = column[java.sql.Date]("date")
   val time: Rep[java.sql.Time] = column[java.sql.Time]("time")
 }
   lazy val Geopointtable = new TableQuery(tag => new Geopointtable(tag))
}

I'm trying to insert some values in table:

val db = Database.forConfig("geodb")
val date = java.sql.Date.valueOf(LocalDateTime.now().toLocalDate.toString)
val time = java.sql.Time(LocalDateTime.now().toLocalTime)
var point = TableQuery[Tables.Geopointtable]

Await.result(
  db.run(
  point  = Tables.GeopointtableRow(1, 2, 3, date, time))
, Duration.Inf)

But for line "Tables.GeopointtableRow(1, 2, 3, date, time))" compiler specify on 2 type mismatches:

  1. Required String, Found Tables.GeopointtableRow".
  2. Required DBIOAction[NotInferedR, NoStream, Nothing], Found Unit

Mismatch

CodePudding user response:

You need to tell Slick which table to insert the record into. You probably want something like

db.run(
  Tables.Geopointtable  = Tables.GeopointtableRow(1, 2, 3, date, time)
)

CodePudding user response:

The problem is solved.

I only import in my class following dependencies: "Tables." and "Tables.profile.api.".

So now I apply to generated table not by "Tables.Geopointtable", but directly - "Geopointtable".

I wonder, why this import was not suggested to add by my IDEA, of cause. ))

  • Related