Questions tagged [slick-2.0]

Slick is a modern database query and access library for Scala by Typesafe. Use this tag for specific issues with features introduced in 2.0. Otherwise use the generic [tag:slick]

Use this tag if your question describes issues with features introduced in 2.0 (January 2014).

Specific Features for 2.0 that might require this tag above the generic :

  • Code generator for reverse-engineering the database schema and code generation
  • Driver architecture to allow support for non-SQL, non-JDBC databases.
  • Syntax in the Lifted Embedding in Table definitions
  • Table definitions (and their * projections)
  • HList abstraction for records of arbitrary size
  • Soft inserts
  • The new model for pre-compiled queries
  • dynamicSession (replaced threadLocalSession)
  • server-side Option conversions
  • Changes to the API for Scala Collections syntax.
  • direct embedding (improved)
  • Query scheduling
  • The code generator phase
  • Full type information available in query ASTs

Adapted from the release notes

195 questions
17
votes
1 answer

Slick - Filter Row if Column is Null

How do I filter rows in Slick if a column is null? val employees = Queryable[Employees] // Error val query = employees.filter( _.terminationDate == Nil ) Might be important to note that terminationDate: Option[String] I am using Direct…
BAR
  • 15,909
  • 27
  • 97
  • 185
16
votes
3 answers

How to COUNT(*) in Slick 2.0?

According to the Slick 2.0 documentation, to get the count of rows in a table: val q1 = coffees.length // compiles to SQL (simplified): // select count(1) from "COFFEES" However, it turns out that coffees.length is of type Column[Int]. How…
kes
  • 5,983
  • 8
  • 41
  • 69
14
votes
1 answer

How to do "OR" filter in slick

In slick we can use query.filter( m => (m.state === state1 && m.status === status1) || (m.state === state2 && m.status == status2)) for an "OR" condition in where clause. However my requirement is I have "OR" conditions in a list (passed by user…
Gaurav
  • 331
  • 2
  • 9
12
votes
2 answers

Printing interpolated SQL query in Slick

I am trying to print an interpolated Slick2 SQL statement for debugging and all I get is the one with question marks e.g. def query(name: String) = sql"SELECT MAX(age) FROM users WHERE name = $name".as[Int] println(query("Bob").getStatement) The…
pathikrit
  • 32,469
  • 37
  • 142
  • 221
12
votes
1 answer

Slick - Compiled with dynamic sortBy

I know as of slick 2.1. one can use ConstColumn for take and drop in precompiled Query's using "Compiled". private val findXXXCompiled = Compiled { (someId:Column[Long], sortBy:???, drop:ConstColumn[Long], take:ConstColumn[Long]) => val q…
tfh
  • 620
  • 1
  • 4
  • 14
11
votes
1 answer

How to select max, min in same query in slick

I want to do this SELECT MAX(age), MIN(age) FROM users WHERE name = 'Rick'. The best I came up with involves 2 queries: Users.filter(_.name === 'Rick').map(_.age).max
pathikrit
  • 32,469
  • 37
  • 142
  • 221
11
votes
1 answer

Infer multiple generic types in an abstract class that should be available to the compiler

I am working on an abstract CRUD-DAO for my play2/slick2 project. To have convenient type-safe primary IDs I am using Unicorn as additional abstraction and convenience on top of slicks MappedTo & ColumnBaseType. Unicorn provides a basic CRUD-DAO…
Floscher
  • 438
  • 3
  • 10
9
votes
3 answers

Slick - Update full object or more than 22 columns

I've a table user_permissions which has 46 permission columns along with id and created_date. This table has a corresponding UserPermissions class: class UserPermission(val id: Long, val createdDate: Option[Timestamp], val permission1: Boolean, …
Sunil Kumar
  • 622
  • 1
  • 12
  • 33
9
votes
2 answers

Filtering when using custom column type in Slick

I'm having some difficulties querying/filtering in Slick 2.1.0 when using a custom column type. A simplified version of my problem: import scala.slick.driver.MySQLDriver.simple._ sealed class Status(val intValue: Int) case object Active extends…
ulejon
  • 631
  • 5
  • 22
8
votes
2 answers

Slick Repo methods all participating in one Service's Transaction

I currently have a set of Data Access Objects named with the convention *SlickRepo. So for instance, UserSlickRepo, DistributionSlickRepo, ContentSlickRepo, etc... Each of these Repos have methods on them that basically follow this convention: trait…
ThaDon
  • 7,826
  • 9
  • 52
  • 84
8
votes
1 answer

Deciphering one of the toughest scala method prototypes (slick)

Looking at the <> method in the following scala slick class, from http://slick.typesafe.com/doc/2.1.0/api/index.html#scala.slick.lifted.ToShapedValue, it reminds me of that iconic stackoverflow thread about scala prototypes. def <>[R, U](f: (U) ⇒…
matanster
  • 15,072
  • 19
  • 88
  • 167
8
votes
1 answer

sbt plugin dynamically load user defined code?

I am working on a sbt plugin that generates Scala models given a database using Slick code generator I would ofcourse want users to override the code generator so my plugin needs to support this: Anyway I can dynamically load a Scala class given a…
pathikrit
  • 32,469
  • 37
  • 142
  • 221
8
votes
2 answers

How do I correctly compare Options members in Slick?

I'm doing things with Addresses, and the member subpremise(apartment/condo #) causes retrieves to miss. I also have concerns about subpremise being a part of my unique index constraint, given it can be null. Failure filter: tableQuery.filter(c=>…
8
votes
1 answer

Scala Slick 2 join on multiple fields?

how can do joins on multiple fields like in example beneath? val ownerId = 1 val contactType = 1 ... val contact = for { (t, c) <- ContactTypes leftJoin Contacts on (_.id === _.typeId && _.ownerId === ownerId) if t.id === contactType } yield…
Vlad Miller
  • 2,255
  • 1
  • 20
  • 38
8
votes
2 answers

How to use DateTime in Slick2.0?

I want to use DateTime in Slick 2.0 model. I use jodatime: I added the dependencies in Build.scala: "joda-time" % "joda-time" % "2.3", "org.joda" % "joda-convert" % "1.6" I then do: class Comment(tag:Tag) extends Table[(Long, Int, Int,…
user504909
  • 9,119
  • 12
  • 60
  • 109
1
2 3
12 13