Suppose I have a table with a number of small columns, and a large (say BLOB) column:
case class Thing(id: Int, small1: String, small2: String, small3: String, large: String)
class ThingMapping(tag: Tag) extends Table[Thing](tag, "things") {
def id = column[Int]("id", O.PrimaryKey, O.NotNull, O.AutoInc)
def small1 = column[String]("small1")
def small2 = column[String]("small2")
def small3 = column[String]("small3")
def large = column[String]("large")
def * = (id, small1, small2, small3, large) <> (Thing.tupled, Thing.unapply)
}
Under some circumstances, I'd like to query the table for all the columns except the large
column. In others, I'd like to include it. I prefer to use case classes rather than tuples.
Is there good pattern in Slick for doing this?
Options I've considered:
- Having two mappings -- a "skinny" and "fat" mapping.
- Splitting out the large column into a separate table, then joining it in if required.
large
asOption[String]
on theThing
case class and optional in the table definition and then add another selectiondef
likedef allNoLarge = (id, small1, small2, small3)
where you don't select thelarge
field from the db. Then you leave it up to the calling code to pick which selectiondef
is used. – Periodonticsval things = TableQuery[ThingMapping]
. How would that fit in with having multiple selection defs in the mapping? – OnesidedTableQuery
as the starting point, and then use the.map
method on it to produce a new query that only selects certain columns. I'll add an answer showing this. – Periodontics