slick

Slick and bonecp: org.postgresql.util.PSQLException: FATAL: sorry, too many clients already error

跟風遠走 提交于 2019-12-07 09:10:17
问题 Locally when I am developing my application I launch my play2 application using sbt run I love how I can make code changes, and then reload my browser to see my changes. After about roughly 10 code changes or so, I get a postgresql too many connection error (see below). My db connection is using the below DatabaseAccess.scala class. I'm guessing on each reload it is creating a bunch of connections to postgresql. In my Global am currently doing: override def onStart(app: Application) { Logger

Calculate table column using over table on server side

余生颓废 提交于 2019-12-07 05:35:28
Suppose, there are two tables in db: Table registries : Column | Type | --------------------+-----------------------------+--------- registry_id | integer | not null name | character varying | not null ... uploaded_at | timestamp without time zone | not null Table rows : Column | Type | Modifiers ---------------+-----------------------------+----------- row_id | character varying | not null registry_id | integer | not null row | character varying | not null In real world registries is just a csv-file and rows is lines of the files. In my scala-slick application, I want to know how many lines

Recursive tree-like table query with Slick

耗尽温柔 提交于 2019-12-07 03:37:09
问题 My table data forms a tree structure where one row can reference a parent row in the same table. What I am trying to achieve, using Slick, is to write a query that will return a row and all it's children. Also, I would like to do the same, but write a query that will return a child and all it's ancestors. In other words: findDown(1) should return List(Group(1, 0, "1"), Group(3, 1, "3 (Child of 1)")) findUp(5) should return List(Group(5, 2, "5 (Child of 2)"), Group(2, 0, "2")) Here is a fully

The “right” way to use write Slick 3.0 Scala queries in Play Framework

徘徊边缘 提交于 2019-12-07 03:21:00
问题 I'm using Slick 3.0 and (of course) almost all the examples out there cover Slick 2.x. Things have changed and frankly seem more complicated, not less. Here's an example: I want to get an object (a GPPerson) by id. This is what I have right now, and it seems very verbose... more so than Slick 2.x: def get(id: GPID): Option[GPPerson] = Await.result( db.run( people.filter(_.id === id).result), Duration.Inf ).headOption In Slick 2.x things were easier because of the implicits, among other things

Slick 2 - Update columns in a table and return whole table object

流过昼夜 提交于 2019-12-07 01:44:55
问题 How would you update a few columns in a table table while returning the entire updated table when using slick? Assuming SomeTables is some TableQuery , you would typically write a query like this if you want to, for example, add an item to the table (and returning the newly added item) val returnedItem = SomeTables returning SomeTables += someTable How would you do the same if you want to update an item and return the whole back the whole item, I suspect you would do something like this val q

Creating a composition Primary Key using Scala Slick

北战南征 提交于 2019-12-07 00:31:36
问题 I'm trying to use two column's as my primary key for a Scala Slick table. Here is how my table is defined: class NbaPlayerBoxScoreTable(tag : Tag) extends Table[NbaPlayerBoxScore](tag, "player_box_scores") { import com.suredbits.core.db.ColumnMappers._ private val gameTable : TableQuery[NbaGameTable] = TableQuery[NbaGameTable] private val playerTable : TableQuery[NbaPlayerTable] = TableQuery[NbaPlayerTable] def playerId = column[Long]("player_id", O.PrimaryKey) def gameId = column[Long]("game

Slick - Update full object or more than 22 columns

寵の児 提交于 2019-12-06 23:45:37
问题 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, val permission2: Boolean, ... val permission46: Boolean) and slick mapping table class UserPermissions(tag: Tag) extends Table[UserPermission](tag, "users_permissions") { def * = ( id :: createdDate :: permission1 :: permission2 :: ... permission46 ::

How do I disable logging for a specific dependency in SBT?

試著忘記壹切 提交于 2019-12-06 23:39:45
问题 I have the following build.sbt file: version := "0.1" scalaVersion := "2.10.0-RC1" scalacOptions := Seq("-unchecked", "-deprecation", "-encoding", "utf8") resolvers ++= Seq( "sonatype releases" at "https://oss.sonatype.org/content/repositories/releases/", "sonatype snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/", "typesafe repo" at "http://repo.typesafe.com/typesafe/releases/", "spray repo" at "http://repo.spray.io/" ) libraryDependencies ++= Seq( "io.spray" % "spray

Scala Slick Lazy Fetch

让人想犯罪 __ 提交于 2019-12-06 19:37:09
问题 I want to be able to fetch all records from a very big table using Slick. If I try to do this through foreach, for or list fetching; I get an Out Of Memory Exception. Is there any way to use "cursors" with Slick or lazy loading that only fetch the object when needed reducing the amount of memory used? 回答1: Not sure what do you mean by cursors, but you can fetch partial data using pagination: query.drop(0).take(1000) will take the first 1000 records query.drop(1000).take(1000) will take from

How to count results with a filter using Slick?

妖精的绣舞 提交于 2019-12-06 19:19:27
问题 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 = 1 Code I'm using Slick in it's "lifted" form, so here is my piece of code counting the users : Query(Users.where( _.id === 1).length).first Actually what happens here is that Slick alias ScalaQuery, is actually creating a subquery with the filter cause