🔴 Scala Intermediate

What is Slick in Scala?

Answer

Slick (Scala Language-Integrated Connection Kit) is Scala's functional-relational mapper (FRM). It allows writing database queries in Scala instead of SQL strings, with type safety. Define table mapping: class Users(tag: Tag) extends Table[User](tag, "USERS") { def id = column[Long]("ID", O.PrimaryKey, O.AutoInc); def name = column[String]("NAME"); def * = (id, name).mapTo[User] }. Queries compile to SQL: val q = users.filter(_.name === "Alice").result. Run: db.run(q) returns a Future[Seq[User]]. Slick uses Quoted DSL — queries are Scala expressions that Slick translates to SQL. Type safety: the compiler catches type mismatches in queries. Slick supports PostgreSQL, MySQL, SQLite, H2, etc. While powerful, Slick has a steep learning curve. Doobie (using Cats Effect) is a simpler, more SQL-first alternative popular in the functional Scala community.