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
11
votes
1 answer

How to write nested queries in select clause

I'm trying to produce this SQL with SLICK 1.0.0: select cat.categoryId, cat.title, ( select count(product.productId) from products product right join products_categories productCategory on…
wassertim
  • 3,116
  • 2
  • 24
  • 39
11
votes
1 answer

How to specify SLICK Query sortBy column from runtime parameter?

I have the following SLICK query to get paged results for a data table with the name field matching some value criteria and sorted by the name column val q = ThirdParties.where(_.name like…
Magnus Smith
  • 827
  • 2
  • 11
  • 28
11
votes
1 answer

Scala Slick / ScalaQuery BigDecimal creates decimal(10,0) how to allow decimals?

How do I tell Slick to create a Decimal SQL type which allows for decimals? It seems that by default Slick doesn't allows for decimals which I noticed with the below code. It creates a column with the data type decimal(10,0) in MySQL. I have the…
user425367
11
votes
1 answer

How to count results with a filter using Slick?

I face a problem I would like to simplify : (quite sure, I'm doing it wrong in fact). Wanted I would like to count the number of users having an id = 1. In SQL language let's say it is something like this : SELECT COUNT(*) FROM users WHERE id =…
i.am.michiel
  • 10,281
  • 7
  • 50
  • 86
10
votes
1 answer

Iterate over arbitrary-length tuple

I just started with Scala and ran into a problem: Scala has the Types Tuple1, Tuple2, …, Tuple22. Scalaquery returns tuples when iterating over queries. I have now a given class (ZK’s ListitemRenderer), which accepts Objects and populates gui lists…
flying sheep
  • 8,475
  • 5
  • 56
  • 73
9
votes
1 answer

How do I rollback a session in ScalaQuery?

For my unit tests I want to setup a database, populate it with base information and run each tests within a session that rollbacks all changes made to the DB in order to always have a pristine copy for each tests. I'm looking for something like db…
tonicebrian
  • 4,715
  • 5
  • 41
  • 65
9
votes
6 answers

How could I know if a database table is exists in ScalaQuery

I'm trying ScalaQuery, it is really amazing. I could defined the database table using Scala class, and query it easily. But I would like to know, in the following code, how could I check if a table is exists, so I won't call 'Table.ddl.create' twice…
Brian Hsu
  • 8,781
  • 3
  • 47
  • 59
9
votes
2 answers

Slick, how to map a query to an inheritance table model?

Slick, how to map a query to an inheritance table model? i.e, I have table A, B, C A is the "parent" table and B & C are "child" tables What I would like to know is how should I model this using slick so A will be abstract and B & C concrete types,…
server.note
  • 118
  • 6
8
votes
1 answer

ScalaQuery multiple primary key & foreign key

How do we define a multiple primary key and a foreign key in ScalaQuery? object myTable1 extends Table([Int])("myTable1") { def id = column[Int]("id", O PrimaryKey) def * = id } object myTable2 extends Table([Int, Int, Int])("myTable2") { …
JohanSJA
  • 705
  • 2
  • 9
  • 21
8
votes
3 answers

NoSQL (e.g. MongoDB) or RDMS (e.g. PostgreSQL) for new Scala project?

I'm developing a brand new project in Scala. It's just an application for a bunch of CRUD operations, however, because of some eccentric requirements, Play2 or Lift does not fit the bill, so I'm going to develop the application from the ground up.…
Jack
  • 16,506
  • 19
  • 100
  • 167
7
votes
1 answer

scalaquery problem no implicit session

this is a scalaquery query which i want to perform, ... def generateFares(scheduleId:NamedColumn[Int], toCityId:NamedColumn[Int], fromCityId:NamedColumn[Int]):List[(String,Int,String)] = { var list:List[(String,Int,String)] = Nil; val q…
tiran
  • 2,389
  • 1
  • 16
  • 28
6
votes
2 answers

How to use ScalaQuery to insert a BLOB field?

I used ScalaQuery and Scala. If I have an Array[Byte] object, how do I insert it into the table? object TestTable extends BasicTable[Test]("test") { def id = column[Long]("mid", O.NotNull) def extInfo = column[Blob]("mbody", O.Nullable) def *…
Googol Shan
  • 1,255
  • 9
  • 13
6
votes
1 answer

Why does this ScalaQuery statement only delete the odd rows?

When attempting to delete a batch of records, only the odd rows are deleted! val byUser = Orders.createFinderBy(_.userID) byUser(id).mutate(_.delete) If I instead print the record, I get the correct number of rows. byUser(id).mutate{x => x.echo} I…
virtualeyes
  • 11,147
  • 6
  • 56
  • 91
5
votes
2 answers

How do I specify a Postgresql schema in ScalaQuery?

I tried, for instance: object WebCache extends Table[(...)]("myschema.mytable") { ... } But that doesn't work.
Yang
  • 16,037
  • 15
  • 100
  • 142
5
votes
1 answer

Raw result rows with named fields in ScalaQuery?

In ScalaQuery, I can do this to work with the "raw" result rows: for ( x <- queryNA[(String,Int)]("select * from foo")( GetResult(r => (r.<<[String], r.<<[Int])) ) ) { println(x) } But this is entirely positional (r is a…
Yang
  • 16,037
  • 15
  • 100
  • 142