Search code examples
scalacase-classscalatrasorm

BigDecimal precision in Scala case class


I am using SORM as ORM in Scalatra application. I use Create as the initMode so that the tables are created automatically. I have a BigDecimal field as part of a case class, as below:

case class Invoice(invoiceId: String, invoiceAmount: BigDecimal)

There are 2 questions for which I am looking for the answers (might be it is just one answer):

  1. How to set the precision of BigDecimal field?
  2. How to set the precision of database column for invoiceAmount?

Is unboxed tagged types the way to go?


Solution

    1. Tagged types is the only way out to have default precision for BigDecimal in case class.
    2. SORM by default uses DECIMAL(65,30) as the column's datatype for Decimal types. Which means you cannot set the precision of the database column unless you create the tables yourself, or customize StdCreateTable.scala to handle that appropriately.