比较一个光滑查询中的2个日期似乎很难 [英] compare 2 dates in a slick query seems hard
问题描述
地狱
我无法适应以下示例代码: https://github.com/pedrofurla/slick-demo/blob/master/src/main/scala/slickdemo/domain/Person.scala .
I can't adapt this example of code : https://github.com/pedrofurla/slick-demo/blob/master/src/main/scala/slickdemo/domain/Person.scala.
它处理比较光滑查询中日期的功能.困难在于您无法访问日期字段(例如,提取年,月和日),因为查询使用的是列类型.
it deals with the capacity of comparing dates in a slick query. The difficulty is you can't access to the date field(to extract for example the year, the month and the day) because the query uses Column types.
我搜索并找到了上面的示例,但我无法适应它.
I searched and found the example above, but I can't adapt it.
这是我的代码:
表格:
class Personnes( tag : Tag ) extends Table[ Rdv ]( tag, "RDV" ) {
def id = column[ Int ]( "ID", O.PrimaryKey, O.AutoInc )
def nom = column[ String ]( "NOM", O.NotNull )
def prénom = column[ String ]( "PRENOM" )
def sexe = column[ Int ]( "SEXE" )
def télPortable = column[ String ]( "TELPOR" )
def télBureau = column[ String ]( "TELBUR" )
def télPrivé = column[ String ]( "TELPRI" )
def siteRDV = column[ String ]( "SITE" )
def typeRDV = column[ String ]( "TYPE" )
def libelléRDV = column[ String ]( "LIBELLE" )
def numRDV = column[ String ]( "NUMRDV" )
def étape = column[ String ]( "ETAPE" )
def dateRDV = column[ java.sql.Date ]( "DATE" )
def heureRDVString = column[ String ]( "HEURE" )
def statut = column[ String ]( "STATUT" )
def orderId = column[ String ]( "ORDERID" )
def * = ( id.?, nom, prénom, sexe, télPortable, télBureau, télPrivé,
siteRDV, typeRDV, libelléRDV, numRDV, étape, dateRDV, heureRDVString,
statut, orderId ) <> ( Rdv.tupled, Rdv.unapply _ )
}
和方法:
def sqlite_findBetween( début : java.util.Date, fin : java.util.Date ) : List[ Rdv ]= db_sqlite.withSession { implicit db : Session =>
def débutTime:org.joda.time.DateTime = new DateTime(début)
def finTime=new DateTime(fin)
val query = for {
p <- personnes
if (p.dateRDV > débutTime && finTime < p.dateRDV)
} yield p
query.list
}
谢谢!
ps:我忘记了错误:在日期比较附近,我得到了:
ps : I forgot the error : near the date comparison, I get :
Cannot perform option-mapped operation with type: (java.sql.Date, org.joda.time.DateTime) => R for base type: (java.sql.Date, java.sql.Date) => Boolean
ps2:这是实用程序文件:很明显,我已经在类路径中添加了它:
ps2 : here is the utility file : I have obviously added it in the classpath : https://github.com/pedrofurla/slick-demo/blob/master/src/main/scala/slickdemo/dal/JodaTimeSupport.scala, with this :
import models.JodaTimeSupport
package models {
trait sqlite extends JodaTimeSupport {...
推荐答案
除了从java.sql.Date
到org.joda.time.DateTime
创建自己的隐式MappedColumnType
之外,您还可以尝试使用流行的 slick-joda-mapper 在Github上的此处找到.
Aside from creating your own implicit MappedColumnType
from java.sql.Date
to org.joda.time.DateTime
, you can try the popular slick-joda-mapper found here on Github.
这篇关于比较一个光滑查询中的2个日期似乎很难的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!