Questions tagged [scalaquery]
ScalaQuery is a typesafe API / DSL (domain specific language) built on top of JDBC for accessing relational databases in Scala.
99
questions
0
votes
1answer
39 views
SLICK: To insert value in 3 different tables using one slick api call
The question is related to slick:
I have three tables:
1) Users
2)Team2members
3)Team2Owners
In my post request to users, I am passing values of memberOf and managerOf, these values will be inserted ...
1
vote
0answers
75 views
Slick Transaction commited , but not saved in table [Mysql]
I am trying to execute multiple DB actions in the same session. DEBUG logs show transaction Commit, But data not persistent on DB. I am using slick 3.2.3 with Scala Play framework 2.6. How can I ...
0
votes
1answer
44 views
Do DBIOActions composed in for comprehensions always run sequentially?
I know that Futures in Scala, when grouped in for comprehensions, run sequentially unless they are declared outside of the for comprehension (as this article explains). Do DBIOActions work the same ...
0
votes
1answer
140 views
Do Aggregation with Slick
My database structure looks like this:
id | content
I what to get the entry with max id (not just id).
I read the answer How to make aggregations with slick, but I found there is no first method ...
1
vote
0answers
504 views
Slick 3. For Comprehension on query. Can I force to have Option
When I run next Query, I get nothing sometimes. This hapens when no associated breeder founded for my flower sort.
for {
sort <- flowerSorts if sort.id === flowerSortId
sortDetails <- ...
1
vote
1answer
223 views
slick schema leftJoin produce Cartesian product
I have this two tables :
select * from "DEPARTMENTS";
ID | NAME | MANAGER_ID
----+-------+------------
1 | FOO | 1
3 | XXX | 2
4 | dept1 |
(3 rows)
...
0
votes
1answer
99 views
slick schema - fetch joined tables
doing my first steps with slick, I have this Tables
case class Employee(name: String,last: String,department: Option[Int] = None,id: Option[Int] = None)
class Employees (tag: Tag) extends Table[...
11
votes
1answer
6k views
SLICK 3.0 - multiple queries depending on one another - db.run(action)
I am new to Slick 3 and so far I have understood that db.run are asynchronous call. the .map or .flatMap is run once the Future is returned.
The problem in my code below is that all the sub queries ...
1
vote
2answers
2k views
Slick 3.0 - Update columns in a table and return whole table object?
Here is the implementation for Slick 2.
Slick 2 - Update columns in a table and return whole table object
Does anyone have ideas about how to implement this in Slick 3?
2
votes
2answers
3k views
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 ...
3
votes
1answer
1k views
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 ...
3
votes
1answer
1k views
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]
}
...
0
votes
2answers
151 views
Trying to do first steps with SLICK but things do not seem to work or documentation is outdated
A custom source code generator was used in order to create the classes necessary for the MySQL database as described in this question: How to setup username and password with Slick's source code ...
1
vote
1answer
102 views
ScalaQuery with play2.1.4
I am migrating play2.0 app to play2.1 which has a lot of scalaquery implemented .
with all the migration changes its finally compiled ( not using anorm) the scalaqueries are still there .
play ...
1
vote
1answer
344 views
Scala Slick Comprehension issues
I have the following in a library:
Case Class:
case class Foo(
id: Option[Long],
bar: Long
...
)
Table:
object Foos extends Mapper[Foo]("foo"){ //I'm using slick-inegration so the id is free
...
16
votes
1answer
9k views
Slick and filtering by Option columns
I'm trying to filter against an optional date column with Scala Slick 1.0.1.
It may be I just don't see it, but I've got a table that looks something like this:
case class UserRole(id:UUID, userID:...
12
votes
5answers
13k views
Select single row based on Id in Slick
I want to query a single row from user based on Id. I have following dummy code
case class User(
id: Option[Int],
name: String
}
object Users extends Table[User]("user") {
def id = column[...
0
votes
1answer
1k views
How to reference a column by name in slick plain SQL?
I would like to use named references instead of positional in GetResult, so that instead of this:
implicit val getCoffeeResult = GetResult(r => Coffee(r.<<, r.<<, r.<<))
i could ...
27
votes
1answer
12k views
How to make aggregations with slick
I want to force slick to create queries like
select max(price) from coffees where ...
But slick's documentation doesn't help
val q = Coffees.map(_.price) //this is query Query[Coffees.type, ...]
...
9
votes
2answers
2k views
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 ...
3
votes
1answer
2k views
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: ...
0
votes
2answers
1k views
How to use Scala's Slick sql interpolation with owner/schema name-prefixes
We have a database setup where we have a separate user for owners and users of database tables in an Oracle database. This means that in practice each query is prefixed like this: ownername.tablename
...
11
votes
1answer
5k views
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 ...
31
votes
2answers
13k views
How to use SQL “LIKE” operator in SLICK
Maybe a silly question. But I have not found an answer so far. So how do you represent the SQL's "LIKE" operator in SLICK?
10
votes
1answer
9k views
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 criteria)....
5
votes
2answers
3k views
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)
} ...
11
votes
1answer
2k views
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 ...
0
votes
1answer
2k views
How to parametrize Scala Slick queries by WHERE clause conditions?
Assume these two simple queries:
def findById(id: Long): Option[Account] = database.withSession { implicit s: Session =>
val query = for (a <- Accounts if a.id === id) yield a.*
query.list....
89
votes
2answers
17k views
scala slick method I can not understand so far
I try to understand some Slick works and what it requires.
Here it an example:
package models
case class Bar(id: Option[Int] = None, name: String)
object Bars extends Table[Bar]("bar") {
def id =...
4
votes
1answer
938 views
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 = ...
2
votes
1answer
146 views
Unsupported length() function generated for SQLite in scalaquery
When trying to use scalaquery to retrieve the length of a text column in a SQLite database it generates the wrong SQL.
I get this:
SELECT "t1"."title" FROM "GoodPages" "t1" WHERE ({fn length("t1"."...
0
votes
1answer
130 views
Scalaquery generating invalid sql on join onto the same table
I have a query that needs to left join onto the same table to find the latest row of an account.
val all = for {
Join(s,s1) <- Subscriptions leftJoin Subscriptions
on ((a,b) ...
2
votes
2answers
166 views
different development/production databases in scalaquery
ScalaQuery requires (AFAIK) to use an provider specific import in your code, for example:
import org.scalaquery.ql.extended.H2Driver.Implicit._
We are trying to use H2 in development mode and MySQL ...
5
votes
1answer
3k views
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=...
4
votes
1answer
3k views
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 ...
0
votes
1answer
994 views
Scala Slick: Query using direct embedding doesn't work
I use the following code to request items from a mysql table (The Account class just is a case class representing the database fields)
val res = Queryable[Account].map(_.name)
val db = Database....
1
vote
1answer
252 views
How can I limit my query by date using ScalaQuery
I'm using Scalaquery and have run into a problem when I attempt to limit my query based on a date field. I'm using Scala 2.9.2, ScalaQuery 2.9.1:0.10.0-M1 Consider the code below:
case class MyCase (...
2
votes
1answer
767 views
Get auto increment key in scalaquery
I want to insert rows in 2 tables which represent a 1:n relationship using scalaquery / slick.
The tables are defined as follows:
object CompanyBaseTable extends Table[CompanyBaseTableEntry]("...
11
votes
1answer
5k views
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 ...
12
votes
1answer
4k views
Select rows based on MAX values of a column in ScalaQuery/SLICK
Say that i have table such as:
UserActions
UserId INT
ActionDate TIMESTAMP
Description TEXT
that holds dates where users perfomed certainActions. If i wanted to get the last action that ...
1
vote
1answer
143 views
Unpack a NamedColumn in a condition of a for-loop in ScalaQuery
I am quite new to Scala and ScalaQuery, using it a couple of weeks now. I am trying to figure out a condition in a query by calling a function, but I get a NamedColumn[T] instead of T, how to unpack ...
1
vote
1answer
955 views
ScalaQuery and Play framework: Best practice for handling unassigned (AutoInc) primary keys
I am using Play 2.0.2 with ScalaQuery 0.9.5.
I have the following simple model code:
case class Task(id: Long, name: String)
object Task extends Table[(Long, String)]("task") {
lazy val database = ...
2
votes
1answer
1k views
MySQL driver not found with Play 2.0
I'm trying to use ScalaQuery with play 2 but I keep getting a ""no suitable driver for ...' error. The database connection works fine with Anorm/Nina.
Here's my ScalaQuery code :
object Client ...
22
votes
2answers
3k views
How do I abstract the domain layer from the persistence layer in Scala
UPDATE:
I've edited the title and added this text to better explain what I'm trying to achieve: I'm trying to create a new application from the ground up, but don't want the business layer to know ...
16
votes
1answer
4k views
How can I present a many-to-many relationship using a link table with ScalaQuery or SLICK?
I've asked a similar question recently, and got a great reply on solving a many-to-many relationship problem with Lift Mapper. I looked at the ScalaQuery/SLICK documentation but it does not document ...
2
votes
1answer
985 views
How do I model a relational database link-table with Scala?
I need to do quite a few many to many mapping of objects in Scala and save it to a relational database.
Here is a fake example to simplify the problem:
Let's say we want to model lecture rooms and ...
3
votes
1answer
558 views
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....
0
votes
1answer
922 views
Slick (Scalaquery) - insert gives type error
I am using Slick (Scalaquery) in my play framework application. According to slick tutorial - I can define a projection for columns I want to insert into. (I am defining this projection because my ...
16
votes
2answers
14k views
Play framework + SLICK (Scalaquery) tutorial
Does anybody know of a good tutorial or a sample project (github) of using Play framework with SLICK (ScalaQuery)? I am struggling to make them work together.
I am getting this error:
[info] play - ...
7
votes
3answers
3k views
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 ...