我正在使用电梯(很棒!)用于网络应用程序,我很困惑使用什么 - 光滑或映射器。 我之前使用过mapper和app。它运作良好但我发现了一个问题。假设我想基于多个过滤器查询数据库,这些过滤器可能存在也可能不存在,我无法想出办法。例如
class Gig extends LongKeyedMapper[Gig]{
def primaryKeyField = id
def getSingleton = Gig
object id extends MappedLongIndex(this) {
override def dbColumnName = "id"
override def dbIndexed_? = true
}
object slug extends MappedString(this, 250) {
override def dbColumnName = "slug"
override def dbNotNull_? = true
}
object status extends MappedEnum(this, GigStatus) {
override def dbColumnName = "status"
override def dbIndexed_? = true
override def targetSQLType(field: String) = Types.TINYINT
}
object title extends MappedString(this, 150) {
override def dbColumnName = "title"
override def uniqueFieldId = Full("gig_title")
override def dbNotNull_? = true
override def validations = valMinLen(5, "Please add a proper title.") _ :: valMaxLen(150, "Title can not exceed 150 characters") _ :: super.validations
}
object description extends MappedText(this) with StringValidators{
override def dbColumnName = "description"
override def uniqueFieldId = Full("gig_desc")
override def dbNotNull_? = true
protected def valueTypeToBoxString(in: String): Box[String] = {
Full(this.is)
}
protected def boxStrToValType(in: Box[String]): String = {
in openOr null
}
def maxLen = 200
override def validations = valMinLen(30, "Please add a proper description.") _ :: Nil
}
object locked extends MappedBoolean(this) {
override def dbColumnName = "locked"
}
object amount extends MappedDouble(this) {
override def dbColumnName = "amount"
override def uniqueFieldId = Full("gig_amount")
override def dbNotNull_? = true
}
object category extends MappedLongForeignKey(this, Category) {
override def dbColumnName = "category"
override def uniqueFieldId = Full("gig_category")
override def dbNotNull_? = true
override def validations = categoryExists _ :: super.validations
def categoryExists(id: Long): List[FieldError] = {
Category.findByKey(id) match {
case Full(cat) => Nil
case _ => List(FieldError(this, "Invalid category selected"))
}
}
}
object createdOn extends MappedDateTime(this) {
override def dbColumnName = "created_on"
}
object updatedOn extends MappedDateTime(this) {
override def dbColumnName = "updated_on"
}
object createdBy extends MappedLongForeignKey(this, User) {
override def dbColumnName = "created_by"
}
object updatedBy extends MappedLongForeignKey(this, User) {
override def dbColumnName = "updated_by"
}
def canApply: Boolean = {
User.currentUser.map(user => user.provider_? && !user.id.is.equals(createdBy.is)) openOr false
}
def myUrl = "/gigs/"+id.is+"/"+slug.is
def editUrl = "/gigs/"+id.is+"/edit"
def unlockUrl = "/payment?id="+this.id.is+"&type=gig&action=unlock"
def hasAnyBidsByUser(user: User): Boolean = {
Bid.get(this, user).size match {
case 0 => false
case _ => true
}
}
def locked_? = this.locked.is
def bidsCount = Bid.getBidsCount(this)
def isOwner(user: User): Boolean = user.id.is.equals(this.createdBy.is)
}
假设我要查询金额= 10且title ='Sample'的演出。其中任何一个或都不存在。当我在java中工作时使用hibernate时,我习惯根据条件添加条件,如果金额!= null将数量添加到条件中,如果title!= null则将标题添加到标准。我使用findAllByInsecureSql
在mapper中使用本机sql做到了这一点我不知道这是不是最好的方式。
目前我正在尝试使用电梯进行浮油。我找不到任何有关如何使其工作的资源。有人可以指出我应该使用什么方向正确的方向。 Mapper或Slick以及将光滑与电梯整合的任何好资源。