【问题标题】:Slick 3.3.0 and custom "def *" projectionSlick 3.3.0 和自定义“def *”投影
【发布时间】:2019-03-19 22:34:49
【问题描述】:

我将 slick 3.3.0 与 Scala 2.12.8 和自定义 def * 方法用于具有超过 22 个字段的案例类。我仍然得到too many elements for tuple: 23, allowed: 22

我做错了什么?

class DealerTable(tag: Tag) extends Table[Dealer](tag, "dealer") {

  import CustomConverters._

  def id = column[Int]("id", O.PrimaryKey, O.AutoInc)

  def sellId = column[String]("sell_id", O.Unique)

  def customerId = column[Int]("customer_id", O.Unique)

  def fake = column[Boolean]("fake", O.Default(false))

  def companyName = column[String]("company_name")

  def district = column[String]("district")

  def street = column[String]("street")

  def postcode = column[String]("postcode")

  def city = column[String]("city")

  def country = column[Country]("country")

  def firstName = column[String]("first_name")

  def lastName = column[String]("last_name")

  def gender = column[Option[Gender]]("gender")

  def email = column[String]("email")

  def phone = column[String]("phone")

  def mobilePhone = column[String]("mobile_phone")

  def subscriptionEndDate = column[Option[LocalDate]]("subscription_end_date")

  def culture = column[Culture]("culture")

  def rating = column[Float]("rating")

  def minPrice = column[Option[Int]]("min_price")

  def maxPrice = column[Option[Int]]("max_price")

  def createdAt = column[ZonedDateTime]("created_at")

  def updatedAt = column[ZonedDateTime]("updated_at")

  def * =
    (
      id,
      sellId,
      customerId,
      fake,
      companyName,
      district.?,
      street,
      postcode,
      city,
      country,
      firstName,
      lastName,
      gender,
      email,
      phone,
      mobilePhone.?,
      subscriptionEndDate,
      culture,
      rating.?,
      minPrice,
      maxPrice,
      createdAt.?,
      updatedAt.?
    ) <> ((Dealer.apply _).tupled, Dealer.unapply)
}

final case class Dealer(id: Int,
                        sellId: String,
                        customerId: Int,
                        fake: Boolean = false,
                        companyName: String,
                        district: Option[String],
                        street: String,
                        postcode: String,
                        city: String,
                        country: Country,
                        firstName: String,
                        lastName: String,
                        gender: Option[Gender],
                        email: String,
                        phone: String,
                        mobilePhone: Option[String],
                        subscriptionEndDate: Option[LocalDate],
                        culture: Culture,
                        rating: Option[Float],
                        minPrice: Option[Int],
                        maxPrice: Option[Int],
                        createdAt: Option[ZonedDateTime] = None,
                        updatedAt: Option[ZonedDateTime] = None)

【问题讨论】:

    标签: scala slick


    【解决方案1】:

    Scala 2.12.8 中没有超过 22 个元素的元组。

    这里是def * = ( id, sellId, ... 你正在尝试创建这样的元组。

    22 Column limit for procedures

    Slick - Update full object or more than 22 columns

    https://lihaimei.wordpress.com/2016/03/30/slick-1-fix-more-than-22-columns-case/

    【讨论】:

    • 谢谢你的回答,我明白了。什么是最直接的方法,用最少的样板代码和对映射案例类(示例中的经销商)进行最少必要的修改来实现def *。你会推荐哪种方式?
    猜你喜欢
    • 2014-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-23
    • 2018-04-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多