Ich stieß auf eine Bedingung, die für die Liste der Zahlen in Slick-3 zu filtern. Hier ist meine Entität.Filter für die Liste der Zahlen in Slick 3
case class Company(id:Long, name: String, companyTypeId: Option[List[Long]] = None)
implicit def GetResultCompany(implicit e0: GR[Long], e1: GR[String], e2: GR[Option[List[Long]]]): GR[Company] = GR{
prs => import prs._
CompanyTest.tupled((<<[Long], <<[String],<<?[List[Long]]))
}
class CompanyTable(_tableTag: Tag) extends Table[Company](_tableTag, Some("base"), "Company") {
def * = (id, name,companyTypeId) <> (CompanyTest.tupled, CompanyTest.unapply)
def ? = (Rep.Some(id), Rep.Some(name), companyTypeId).shaped.<>({r=>import r._; _1.map(_=> CompanyTest.tupled((_1.get, _2.get _3)))}, (_:Any) => throw new Exception("Inserting into ? projection not supported."))
val id: Rep[Long] = column[Long]("CompanyId", O.AutoInc, O.PrimaryKey)
val name: Rep[String] = column[String]("Name", O.Length(250,varying=true))
val companyTypeId: Rep[Option[List[Long]]] = column[Option[List[Long]]]("CompanyTypeId", O.Length(19,varying=false), O.Default(None))
}
lazy val companyTable = new TableQuery(tag => new CompanyTable(tag))
Hier mag ich für companyTypeId
suchen und es ist Option[List[Long]]
ich von companyTable.filter(_.companyTypeId === Some(List(1,2)))
versucht zu tun, aber immer Vector()
und die Tabelle eine Reihe von Daten mit companyTypeId ist, wie {1} .Ich Postgres ist mit DB.
Vielen Dank im Voraus.
Wie funktioniert die Einheit Blick in die Datenbank? Speichern Sie wirklich eine Liste von Werten in einer Spalte? –
@Gregor Raýman ... ja es sieht aus wie {1,2,3} und der Datentyp ist bigint [] – Jet
Interessant. Ich nehme an, es normalisieren, eine andere verknüpfte Tabelle ist keine Option für Sie. Ich bin mir nicht sicher, wie die eingebaute Unterstützung von Slick for Array-Spalten ist, aber dieses [thread] (https://groups.google.com/forum/#!topic/scalaquery/v7lhyCd8_6k) könnte hilfreich sein. –