Questions tagged [scalaquery]

ScalaQuery is a typesafe API / DSL (domain specific language) built on top of JDBC for accessing relational databases in Scala.

The low-level JDBC API is powerful but comes with a lot of verbosity. ScalaQuery was designed from the ground up to reduce the amount of boilerplate required and make use of Scala's features to provide a more natural fit for database access in a Scala environment.

The basic idea is that tables in the database get represented as objects extending a Table trait. This object can then be used in for comprehension extremely similar to normal Scala collection.

ScalaQuery is not an ORM, i.e. it doesn't do caching, tracking of objects for change or similar things. It is more a way to replace or generate SQL.

NOTE: Since early 2012, ScalaQuery has evolved into Slick.

99 questions
5
votes
2 answers

Sorting Slick query results in a for expression

The following function works fine, but I would like it to sort the results first by parent_id, and then by order. def getTree = for { (a, c) <- Activities leftJoin Clients on (_.id === _.id_a) } yield (a.id, a.label, a.parent_id, a.order, c.id.?,…
Jack
  • 16,506
  • 19
  • 100
  • 167
5
votes
1 answer

How to add AND to the join SLICK

I have the problem writing query in SLICK Here is my request to MySql database: SELECT * FROM readings AS r JOIN parameters AS p LEFT JOIN sensorvalues AS sv ON sv.parameter_id=p.id AND sv.reading_id=r.id How can I write it using SLICK ? It is…
Yaroslav
  • 340
  • 3
  • 11
4
votes
2 answers

Scalaquery: filter by “any”-combination of conditions

I want join an arbitrary-length list of filters with or. If the list would be fixed-length, it would look like this: query.filter(filters(0) || filters(1) || … || filter(n)) Joining filters with and would be easy: for (filter ← filters) query =…
flying sheep
  • 8,475
  • 5
  • 56
  • 73
4
votes
1 answer

Using dynamic Datasource with Tomcat

I'm creating a series of webservices for my application and i have the need to access a different database based on the serviceCode that is passed as a parameter in the webservice call. I setup a basic resource with tomcat to access a database like…
Gades
  • 75
  • 1
  • 9
4
votes
1 answer

How is this a "type mismatch"?

found : (Int, String, Option[java.lang.String]) required: (Int, String, Option[java.lang.String]) Pertinent code: object M extends Table[(Int, String, Option[String])]("table") { def msaid = column[Int]("msaid", O NotNull) def name =…
nix
  • 378
  • 1
  • 8
4
votes
1 answer

Describing optional fields in Slick

The Slick DSL allows two ways to create optional fields in tables. For this case class: case class User(id: Option[Long] = None, fname: String, lname: String) You can create a table mapping in one of the following ways: object Users extends…
Jack
  • 16,506
  • 19
  • 100
  • 167
4
votes
2 answers

How to select just one first or last record compliant to a where clause with ScalaQuery?

Having the following query template to select all: val q = for { a <- Parameters[Int] b <- Parameters[Int] t <- T if t.a == a && t.b == b _ <- Query.orderBy(t.c, t.d) } yield t I need to modify it to select the very first (with minimum c…
Ivan
  • 63,011
  • 101
  • 250
  • 382
3
votes
1 answer

How to configure Play! Framework to work with ScalaQuery and H2?

I already have some simple project with one migration script: # --- !Ups create table user ( name varchar(255) not null primary key, password varchar(255) not null ); insert into user values ('demo', 'demo'); insert into user values…
Piotr Kukielka
  • 3,792
  • 3
  • 32
  • 40
3
votes
1 answer

How do you modify existing records using ScalaQuery?

By modify I mean counterparts of SQL UPDATE and DELETE. In both cases I have an object-record and I would like to delete it in the database. The table has always primary key, and it is set in my object-record. Please note that I don't have query or…
greenoldman
  • 16,895
  • 26
  • 119
  • 185
3
votes
2 answers

Dynamic OR filtering - Slick

Ok, I've got a method with multiple optional arguments like this def(username: Option[String], petname: Option[String], favouritefood: Option[String]) and i want to write a dynamic query that will be capable of fetching the data of defined…
bgvoka
  • 65
  • 1
  • 4
3
votes
1 answer

Slick dynamic optional query or OR filter

I have an issue that I cannot solve for few days, I'd like to make a dynamic query depending on my optional value. If a value is defined, I want to query for the selected results, otherwise to give me * projection of the table. As it is impossible…
bgvoka
  • 65
  • 1
  • 4
3
votes
1 answer

Slick: CRUD extension: How to encapsulate implicit mapping:BaseColumnType[T]

There is the following API for Slick CRUD (Slick-2.1.0, Scala-2.11.4): trait HasId { type Id def id: Option[Id] } trait HasIdColumn[E <: HasId] { def id: scala.slick.lifted.Column[E#Id] } trait SlickExtensions { val driver:…
John Mullins
  • 1,061
  • 4
  • 11
  • 38
3
votes
1 answer

Why the slick projections do not work

For some reason, in my case, even the simple Slick table declaration is not working. I am using slick 2.10 (1.0.0), which is the latest from the maven central repository. case class DeviceType(id: Option[Int] = None, name: String, version:…
Salil
  • 9,534
  • 9
  • 42
  • 56
3
votes
1 answer

Configure ScalaQuery in a Play 2.0 project

I wanted to try out using ScalaQuery with the Play! Framework (version 2.0.2) but I can't get it to work. I added the following line to the Build.scala file : val appDependencies = Seq( "org.scalaquery" %% "scalaquery" % "0.9.5" ) But when…
user1502150
  • 357
  • 1
  • 4
  • 11
3
votes
2 answers

ScalaQuery many to many

Do anybody have an Idea of how to archive many to many in Scala Query? I want to connect a blog post to a series of tags. This is my database design: I have succeeded with my custom code but when inspecting Scala Querys generated SQL I'm not happy…
user425367