slick

Comparing type mapped values in Slick queries

久未见 提交于 2019-12-05 12:17:59
Consider the Favorites table object below, we want to write a query to find Favorites by their type (defined below). We have also defined a Typemapper, to map a FavoriteType to a String for the database import scala.slick.driver.PostgresDriver.simple._ //Other imports have been omitted in this question object Favorites extends Table[Favorite]("favorites") { // Convert the favoriteTypes to strings for the database implicit val favoriteMapping: TypeMapper[FavorietType] = MappedTypeMapper.base[FavorietType, String]( favType => FavorietType.values.find(_ == favType).get.mapping, mapping =>

Generic CRUD operations using Slick 2.0

落爺英雄遲暮 提交于 2019-12-05 11:50:53
I am trying to write a generic CRUD trait for Slick 2.0. The trait should a) provide generic methods to read/update/delete entities as well as b) abstract from the database. Following this slick example (database abstraction) and this article (CRUD trait) I came up with the following (shortened) code snippet: trait Profile { val profile: JdbcProfile } trait Crud[T <: AbstractTable[A], A] { this: Profile => import profile.simple._ val qry: TableQuery[T] def countAll()(implicit session: Session): Int = { qry.length.run } def getAll()(implicit session: Session): List[A] = { qry.list // <-- type

Dynamic order by in scala slick with several columns

荒凉一梦 提交于 2019-12-05 11:26:53
I have been learning scala, playframework and slick, but i have found a problem. I am trying to make a simple CRUD, with a list controllers that receives a custom filter field, some pagination info (page size and number) and a Seq of string tuples with the field name and the order (asc or desc), and everything is working fine, except for the order by seq, i can not make the order by dynamic. I got the basic structure from Scadiddle blog . So, the basic code is as follows: I have my basic color model: case class Color( id: Int, name: String) It is a simple table definition: class ColorsTable

Recursive tree-like table query with Slick

老子叫甜甜 提交于 2019-12-05 08:06:13
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 functional worksheet (except for the missing solutions ;-). package com.exp.worksheets import scala

How to use a Non Supported Database in Slick 3.1

无人久伴 提交于 2019-12-05 08:02:49
In the past I have used Slick to access a Vertica database in a server. I recently upgraded my version of Slick from 2.0 to 3.1. Since the upgrade, I am encountering an error (stack trace below). The error indicates that the slick driver cannot be found. According to the Slick 3.2.1 docs , "Other SQL databases can be accessed right away with a reduced feature set". What I am wondering is - Is it still possible to use an "Other" type of database from those directly supported by slick? If so, how? My database config is: slick.dbs.default.driver="slick.driver.JdbcDriver" slick.dbs.default.db

Dynamically changing the database shard that I am connecting too

懵懂的女人 提交于 2019-12-05 06:18:37
问题 I want to have a pool of database connections, connecting to various sharded databases. On a per query basis I will pass in the tenant/customerId, and based on the customerId I will choose which database to connect and use for the current query. Is this something that can be done with Slick out of the box? 回答1: Not supported out of the box, but shouldn't be too hard to implement I think. I created a ticket: https://github.com/slick/slick/issues/703 来源: https://stackoverflow.com/questions

slick exception when trying to connect to MySql

若如初见. 提交于 2019-12-05 04:47:35
I am trying to follow the slick2 examples using MySql. however when trying to connect to the database I am getting end exception import scala.slick.driver.MySQLDriver.simple._ import slickTest.DB.SuppliersEntity object slickTestDB { def main(args: Array[String]) { println("CreateDb!") val schemaName = "slickTest" val conn_str = "jdbc:mysql://localhost:3306/" + schemaName val database = Database.forURL(conn_str,user="",password="",driver="com.mysql.jdbc.Driver") } } getting this exception Exception in thread "main" java.lang.ClassNotFoundException: com.mysql.jdbc.Driver at java.net

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

折月煮酒 提交于 2019-12-05 04:35:26
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 = SomeTables.filter(_.id === id).map(x => (x.someColumn,x.anotherColumn)) returning SomeTables val

Creating a composition Primary Key using Scala Slick

耗尽温柔 提交于 2019-12-05 04:25:19
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_id", O.PrimaryKey) def lastUpdated = column[DateTime]("last_updated") def min = column[String]("min")

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

*爱你&永不变心* 提交于 2019-12-05 04:08:46
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-can" % "1.1-M4.2" ,"io.spray" % "spray-routing" % "1.1-M4.2" ,"io.spray" % "spray-testkit" % "1.1-M4.2"