How to compare column [option [DateTime] with DateTime.now on slick 3.0 filter

I have the following problem.

im using spray.http.DateTime and my cartographer:

  implicit val JavaUtilDateTimeMapper =
    MappedColumnType.base[DateTime, Timestamp] (
      d => new Timestamp(d.clicks),
      d => spray.http.DateTime(d.getTime))


 case class EventosModelTable(
  id: Option[Long],
  idCliente: Option[Long],
  idPlan: Option[Long] = None,
  idServicio: Option[Long] = None,
  tipo: TipoEventos.Value,
  fechaInicio: DateTime,
  fechaFin: Option[DateTime]
) extends BaseModel

class EventosTabla(tag: Tag) extends Table[EventosModelTable](tag, "eventos") with BaseTabla{

  override def id = column[Long]("id", O.PrimaryKey, O.AutoInc)
  def idCliente = column[Long]("id_cliente")
  def idPlan = column[Option[Long]]("id_plan")
  def idServicio = column[Option[Long]]("id_servicio")
  def tipo = column[TipoEventos.Value]("tipo_evento")
  def fechaInicio = column[DateTime]("fecha_inicio")
  def fechaFin = column[Option[DateTime]]("fecha_fin")

  def * = (id.?,idCliente.?,idPlan,idServicio,tipo,fechaInicio,fechaFin) <> (EventosModelTable.tupled, EventosModelTable.unapply _)

  def cliente = foreignKey("cliente",idCliente,TableQuery[ClientesTabla])(_.id)
  def plan = foreignKey("plan",idPlan,TableQuery[PlanesTabla])(_.id)
}

      

then .. I need to find an event where fechaFin is Null or fechaFin> DateTime.now ... but the problem is that fechaFin can be Null, then it is an Option value and I cannot compare to DateTime.now .. compilation error is that Some [DateTime] doesn't have a> method.

I would be grateful for any help

the request looks like this.

def getAltasBajas(id : Long) : DBIOAction[Seq[EventosModelTable],NoStream,Effect.All] = {

      val q = for {
        altasBajas <- tabla.filter(_.idCliente === id)
            if altasBajas.fechaFin.isEmpty || (altasBajas.fechaFin.isDefined && (altasBajas.fechaFin)<(DateTime.now))
      }yield altasBajas

      q.result
    }

      

+3


source to share


1 answer


I found this answer which indicates that your implementation should work (at least as far as I can see), or you can try



val q = for {
  altasBajas <- tabla.filter(_.idCliente === id)
  if !altasBajas.fechaFin.isNull || altasBajas.fechaFin < DateTime.now
} yield altasBajas

      

+1


source







All Articles