Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    scurtis
    @scurtis
    sorry -
    bind(classOf[JdbcProfile]).to(classOf[slick.driver.MySQLDriver])
    scurtis
    @scurtis
    actually, never mind that question. using play-slick solved that problem. A better question, frankly is - i noticed there didnt seem to be anything within essential slick about writing unit tests/mocks for slick. are there any good resources you can point me to?
    Richard Dallaway
    @d6y
    Hi @scurtis - indeed, there is nothing on testing yet. In-memory h2 testing is what I often end up with. Typically, e.g., in a unit test, setting up and throwing away an in-memory database around a test case. Is that the kind of thing you had in mind?
    Moira Mallison
    @moiramallison
    I'm trying to run the Tables example in Intellij with Maven and I'm getting compile errors :
    Dave Gurnell
    @davegurnell
    @moiramallison I'm here (a little late sorry!). Do paste your errors if you're still having trouble.
    Moira Mallison
    @moiramallison

    Information:Module "dwh-sandbox" was fully rebuilt due to project configuration/dependencies changes
    Information:3/30/2016 3:42 PM - Compilation completed with 2 errors and 0 warnings in 11s 372ms
    Error:scalac:
    while compiling: C:\Users\mmallison\Documents\dwh-sandbox\src\main\scala\actions\Main.scala
    during phase: typer
    library version: version 2.10.6
    compiler version: version 2.10.6
    reconstructed args: -nobootcp -javabootclasspath ; -classpath C:\Program Files\Java\jdk1.7.0_79\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.7.0_79\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.7.0_79\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.7.0_79\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.7.0_79\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.7.0_79\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.7.0_79\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.7.0_79\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.7.0_79\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.7.0_79\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.7.0_79\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.7.0_79\jre\lib\jce.jar;C:\Program Files\Java\jdk1.7.0_79\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.7.0_79\jre\lib\jfxrt.jar;C:\Program Files\Java\jdk1.7.0_79\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.7.0_79\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.7.0_79\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.7.0_79\jre\lib\resources.jar;C:\Program Files\Java\jdk1.7.0_79\jre\lib\rt.jar;C:\Users\mmallison\Documents\dwh-sandbox\target\classes;C:\Users\mmallison.m2\repository\org\postgresql\postgresql\9.4-1206-jdbc42\postgresql-9.4-1206-jdbc42.jar;C:\Users\mmallison.m2\repository\joda-time\joda-time\2.2\joda-time-2.2.jar;C:\Users\mmallison.m2\repository\org\joda\joda-convert\1.3.1\joda-convert-1.3.1.jar;C:\Users\mmallison.m2\repository\com\typesafe\slick\slick_2.11\3.1.0\slick_2.11-3.1.0.jar;C:\Users\mmallison.m2\repository\org\scala-lang\scala-library\2.11.6\scala-library-2.11.6.jar;C:\Users\mmallison.m2\repository\org\slf4j\slf4j-api\1.7.10\slf4j-api-1.7.10.jar;C:\Users\mmallison.m2\repository\com\typesafe\config\1.2.1\config-1.2.1.jar;C:\Users\mmallison.m2\repository\org\reactivestreams\reactive-streams\1.0.0\reactive-streams-1.0.0.jar;C:\Users\mmallison.m2\repository\org\slf4j\slf4j-nop\slf4j-nop\slf4j-nop-slf4j-nop.jar
    last tree to typer: TypeTree(class AlbumTable)
    symbol: class AlbumTable in object Main (flags: )
    symbol definition: class AlbumTable extends slick.driver.PostgresDriver.api.Table[actions.Main.Album]
    tpe: actions.Main.AlbumTable
    symbol owners: class AlbumTable -> object Main -> package actions
    context owners: package <root>
    == Enclosing template or block ==

    <empty>
    == Expanded type of tree ==
    TypeRef(
    pre = ThisType(object Main)
    TypeSymbol(
    class AlbumTable extends slick.driver.PostgresDriver.api.Table[actions.Main.Album]

    )
    )
    uncaught exception during compilation: scala.MatchError
    Error:scalac: Error: false (of class scala.reflect.internal.Trees$Literal)
    scala.MatchError: false (of class scala.reflect.internal.Trees$Literal)

    at scala.tools.nsc.typechecker.Macros$MacroImplBinding$.unpickleAtom(Macros.scala:118)
    
    at scala.tools.nsc.typechecker.Macros$MacroImplBinding$$anonfun$7.apply(Macros.scala:186)
    
    at scala.tools.nsc.typechecker.Macros$MacroImplBinding$$anonfun$7.apply(Macros.scala:186)
    
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
    
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
    
    at scala.collection.immutable.List.foreach(List.scala:318)
    
    at scala.collection.TraversableLike$class.map(TraversableLike.scala:244)
    
    at scala.collection.AbstractTraversable.map(Traversable.scala:105)
    
    at scala.tools.nsc.typechecker.Macros$MacroImplBinding$.unpickle(Macros.scala:186)
    
    at scala.tools.nsc.typechecker.Macros$class.scala$tools$nsc$typechecker$Macros$$loadMacroImplBinding(Macros.scala:
    sorry! I thought I had pasted these...
    Richard Dallaway
    @d6y
    Hello @moiramallison - it looks like your maven project is using Scala 2.10, and the Slick Workshop was prepared for Scala 2.11, so that may be something you’re running into here.
    Moira Mallison
    @moiramallison
    ok thanks - I'll try that...
    Moira Mallison
    @moiramallison
    well, that seems to have fixed that problem. Now I'm getting these:
    C:\Users\mmallison\Documents\dwh-sandbox\src\main\scala\tables\Main.scala
    Error:(8, 8) Main is already defined as object Main
    object Main {
    ^
    C:\Users\mmallison\Documents\dwh-sandbox\src\main\scala\tables\Rating.scala
    Error:(5, 23) Rating is already defined as class Rating
    sealed abstract class Rating(val stars: Int)
    ^
    Error:(7, 8) Rating is already defined as object Rating
    object Rating {
    ^
    the tables directory is the only thing I have in src/main/scala so I'm not sure what it is complaining about
    Richard Dallaway
    @d6y
    @moiramallison possibly your project still contains older compiled versions? I’d suggest removing the target directories (or wherever the classes are compiled to), and trying again. sbt clean with sbt. Not sure what that would be in Maven or IntelliJ… or possibly manaully remove the compiled classes to be sure.
    Alessandro Vermeulen
    @spockz
    Mvn clean and IntelliJ rebuild project
    suraj shrestha
    @surajz_twitter
    On the join,
    code
    val explicitInnerJoin: DBIOAction[Seq[(Artist, Album)], NoStream, Effect.Read] =
    ArtistTable.join(AlbumTable)
    .on { case (artist, album) => artist.id === album.artistId }
    .result
    code
    If I want to get Seq(aritist, Seq(album)) what is a good way to get it. If I have 3 or 4 table joins .
    Richard Dallaway
    @d6y
    @surajz_twitter there’s no Slick-specific way to do that. You’ll want to use regular Scala code after the query runs to aggregate those rows into the structure you want.
    laiboonh
    @laiboonh
    Referring to the explicit joins, i see that the SQL statement is not doing a join it does the same and an implicit join. What gives?
    val query:Query[(AlbumTable,ArtistTable), (Album,Artist), Seq] = AlbumTable join ArtistTable on { (albumTable, artistTable) => albumTable.artistId === artistTable.id } println(query.result.statements)//List(select x2."id", x2."artistId", x2."title", x2."year", x3."id", x3."name", x2."rating" from "albums" x2, "artists" x3 where x2."artistId" = x3."id")
    Richard Dallaway
    @d6y
    Hi @laiboonh - the two styles of query (monadic and applicative) aren’t guaranteed to always produce one style of SQL or another. It’s subject to change.
    Richard Dallaway
    @d6y
    However, the documentation does suggest Slick will do what you expect. I suspect the doco is wrong...
    Richard Dallaway
    @d6y
    I’ve queried it: slick/slick#1716
    suraj shrestha
    @surajz_twitter
    Is there a way to make some columns readonly in slick (similar to how in hibernate you can set some column to updatable = false). I have many tables that has create date and update date. I want them to be managed by database. But, I want it to be read when reading an object, for example user. I can query the database to get the old values, and update the target object with the new values before executing the update. But I wanted to know, if there is an better way.
    Richard Dallaway
    @d6y
    @surajz_twitter I don’t know of any read-only facility like that. The approach I’d explore is a custom update method that takes your object but ignores the fields you want to ignore. E.g., def update(e: Entity): DBIO[Int] = table.filter(_.id === e.id).map(row => (row.column1, row.column2, …etc)).update( (e.column1, e.column2,…etc))
    suraj shrestha
    @surajz_twitter
    Thanks Richard, Regarding the above syntax, . If Entity case class has 5 columns Entity(col1, col2, col3, col4, col5) and if I want to update col1, col2, col3 then col4 and col5 must be optional field with default value for the above syntax to work right? Inside the map and update tuple, can you select any columns or does it need to match the case class for the above syntax to work?
    Richard Dallaway
    @d6y
    The code above produces "update table set col1=?, col2=? where id =?" - so doesn't have to match the case class structure. Select the columns you want in the tuples.
    Matthias Braun
    @mb720

    Hi!
    I just finished reading Essential Slick; great book!

    I was wondering if you had any advice on data modelling, i.e., how to represent the real world domain in Scala types.
    The main issue for me is that I'm used to thinking in nested types (e.g., case classes containing a sequence of another case class which again contains a case class, etc.) which seem to be a bad fit for the relational model.

    • How should my case classes look like when they can't be nested? I guess that for one-to-many relationships we use IDs and foreign keys to determine which objects are related to another object.
    • How do I keep the number of rows that a query returns low, so I don't run into performance problems?

    How do you go about modelling the often complex relationships of real world things in Scala and Slick?

    Thanks a lot in advance,
    Matthias

    Richard Dallaway
    @d6y
    Hi @mb720 - thanks for the feedback. You’re spot on about nesting: it’s a bad fit with Slick/relational. So I keep the datastructures flat. If there are places that really need nesting, you can create a separate case class for those situations.
    You can paginate queries with take and drop, to control how much comes back from a query.
    Matthias Braun
    @mb720
    Thanks for your quick response, @d6y.
    • Do you see any benefits in keeping your datastructures flat, apart from being able to use a relational database?
    • Can you recommend any resources (books, articles) on how to model the world in an application that uses a relational database and thus flat datastructures? Or should I stop worrying since that kind of modelling comes naturally?
    • If you're interested, I can offer a handful of spelling corrections for Essential Slick. Just let me know how to send them to you.
    Richard Dallaway
    @d6y
    @mb720 corrections would be great. You can email me page numbers and the word and I can fix, or if you have them highlight in a PDF, feel free to send me that. I’m richard@underscore.io
    Regarding experiences with Slick and modelling, I’d say take a look down the list of third-party documentation and projects: http://slick.lightbend.com/docs/third-party-slick-3 — I can’t think of one in particular, but if you scan down you may find something that catches you eye. There are also a few talks on the Slick web site.
    Possibly I could pick out Slick in the field, learning to forget ORM: https://www.youtube.com/watch?v=zqt2IdThJXA … that might be useful.
    There’s quite a bit of demonstration of the speaker’s library, and I think the code is from Slick 2, but maybe some useful things in there
    Matthias Braun
    @mb720
    Thanks a lot for the pointers! :+1: I sent you the corrections per mail.
    Richard Dallaway
    @d6y
    Thanks - I’ll get those folded in on the next release.
    Amit Sharma
    @objectamit_twitter
    I checked out the latest code from the Github repo yesterday and running into issues running sbt in the main project directory. I'm on a Mac with JDK 1.8.0_131 and I've got scala 2.12.3 and sbt 1.0.0 using homebrew. As I run sbt in the project directory, the first error that I get is that it could not find artifact ensime-sbt. I opened the file project/plugins.sbt and saw the dependency there. After searching on search.maven.org, I observed that the artifact is actually sbt-ensime with version 2.0.1 while the code had dependency ensime-sbt with version 0.2.1. After changing the artifact and version, when I run sbt again, it complains about sbteclipse-plugin. The console output is pasted below. Can someone guide me?[info] Loading global plugins from /Users/amit/.sbt/1.0/plugins [info] Loading settings from plugins.sbt ... [info] Loading project definition from /Users/amit/Workspaces/scalaWorkspace/scalax15-slick/project [info] Updating {file:/Users/amit/Workspaces/scalaWorkspace/scalax15-slick/project/}scalax15-slick-build... [warn] module not found: com.typesafe.sbteclipse#sbteclipse-plugin;2.5.0 [warn] ==== typesafe-ivy-releases: tried [warn] https://repo.typesafe.com/typesafe/ivy-releases/com.typesafe.sbteclipse/sbteclipse-plugin/scala_2.12/sbt_1.0//2.5.0/ivys/ivy.xml [warn] ==== sbt-plugin-releases: tried [warn] https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/com.typesafe.sbteclipse/sbteclipse-plugin/scala_2.12/sbt_1.0//2.5.0/ivys/ivy.xml [warn] ==== local: tried [warn] /Users/amit/.ivy2/local/com.typesafe.sbteclipse/sbteclipse-plugin/scala_2.12/sbt_1.0//2.5.0/ivys/ivy.xml [warn] ==== public: tried [warn] https://repo1.maven.org/maven2/com/typesafe/sbteclipse/sbteclipse-plugin_2.12_1.0/2.5.0/sbteclipse-plugin-2.5.0.pom [warn] ==== local-preloaded-ivy: tried [warn] /Users/amit/.sbt/preloaded/com.typesafe.sbteclipse/sbteclipse-plugin/2.5.0/ivys/ivy.xml [warn] ==== local-preloaded: tried [warn] file:////Users/amit/.sbt/preloaded/com/typesafe/sbteclipse/sbteclipse-plugin_2.12_1.0/2.5.0/sbteclipse-plugin-2.5.0.pom [warn] :::::::::::::::::::::::::::::::::::::::::::::: [warn] :: UNRESOLVED DEPENDENCIES :: [warn] :::::::::::::::::::::::::::::::::::::::::::::: [warn] :: com.typesafe.sbteclipse#sbteclipse-plugin;2.5.0: not found [warn] :::::::::::::::::::::::::::::::::::::::::::::: [warn] [warn] Note: Some unresolved dependencies have extra attributes. Check that these dependencies exist with the requested attributes. [warn] com.typesafe.sbteclipse:sbteclipse-plugin:2.5.0 (scalaVersion=2.12, sbtVersion=1.0) [warn] [warn] Note: Unresolved dependencies path: [warn] com.typesafe.sbteclipse:sbteclipse-plugin:2.5.0 (scalaVersion=2.12, sbtVersion=1.0) (/Users/amit/Workspaces/scalaWorkspace/scalax15-slick/project/plugins.sbt#L1-2) [warn] +- default:scalax15-slick-build:0.1-SNAPSHOT (scalaVersion=2.12, sbtVersion=1.0) [error] sbt.librarymanagement.ResolveException: unresolved dependency: com.typesafe.sbteclipse#sbteclipse-plugin;2.5.0: not found [error] at sbt.internal.librarymanagement.IvyActions$.resolveAndRetrieve(IvyActions.scala:331) [error] at sbt.internal.librarymanagement.IvyActions$.$anonfun$updateEither$1(IvyActions.scala:205) [error] at sbt.internal.librarymanagement.IvySbt$Module.$anonfun$withModule$1(Ivy.scala:229) [error] at sbt.internal.librarymanagement.IvySbt.$anonfun$withIvy$1(Ivy.scala:190) [error] at sbt.internal.librarymanagement.IvySbt.sbt$internal$librarymanagement$IvySbt$$action$1(Ivy.scala:70) [error] at sbt.internal.librarymanagement.IvySbt$$anon$3.call(Ivy.scala:77) [error] at xsbt.boot.Locks$GlobalLock.withChannel$1(Locks.scala:93) [error] at xsbt.boot.Locks$GlobalLock.xsbt$boot$Locks$GlobalLock$$withChannelRetries$1(Locks.scala:78) [error] at xsbt.boot.Locks$GlobalLock$$anonfun$withFileLock$1.apply(Locks.scala:97) [error] at xsbt.boot.Using$.withResource(Using.scala:10) [error] at xsbt.boot.Using$.apply(Using.scala:9) [error] at xsbt.boot.Locks$GlobalLock.ignoringDeadlockAvoided(Locks.scala:58) [error] at xsbt.boot.Locks$GlobalLock.withLock(Locks.scala:48) [error] at xsbt.boot.Locks$.apply0(Locks.scala:31) [error] at xsbt.boot.Locks$.apply(Locks.scala:28) [error] at sbt.internal.librarymanagement.IvySbt.withDefaultLogger(Ivy.scala:77) [error] at sbt.internal.librarymanagement.IvySbt.withIvy(Ivy.scala:185) [error] at sbt.internal.librarymanagement.IvySbt.withIvy(Ivy.scala:182) [error] at sbt.internal.librarymanagement.IvySbt$Module.withModule(Ivy.scala:228) [error] at sbt.internal.librarymanagement.IvyActions$.updateEither(IvyActions.scala:190) [error] at sbt.librarymanagement.ivy.IvyDependencyResolution.update(IvyDependencyResolution.scala:20) [error] at sbt.librarymanagement.DependencyResolution.update(DependencyResolution.scala:56) [error] at sbt.internal.LibraryManagement$.resolve$1(LibraryManagement.scala:38) [error] at sbt.internal.LibraryManagement$.$anonfun$cachedUpdate$12(LibraryManagement.scala:91) [error] at sbt.util.Tracked$.$anonfun$lastOutput$1(Tracked.scala:64) [error] at sbt.internal.LibraryManagement$.$anonfun$cachedUpdate$19(LibraryManagement.scala:104) [error] at scala.util.control.Exception$Catch.apply(Exception.scala:224) [error] at sbt.internal.LibraryManagement$.$anonfun$cachedUpdate$11(LibraryManagement.scala:104) [error] at sbt.internal.LibraryManagement$.$anonfun$cachedUpdate$11$adapted(LibraryManagement.scala:87) [error] at sbt.util.Tracked$.$anonfun$inputChanged$1(Tracked.scala:141) [error] at sbt.internal.LibraryManagement$.cachedUpdate(LibraryManagement.scala:118) [error] at sbt.Classpaths$.$anonfun$updateTask$5(Defaults.scala:2313) [error] at scala.Function1.$anonfun$compose$1(Function1.scala:44) [error] at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:42) [error] at sbt.std.Transform$$anon$4.work(System.scala:64) [error] at sbt.Execute.$anonfun$submit$2(Execute.scala:257) [error] at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:17) [error] at sbt.Execute.work(Execute.scala:266) [error] at sbt.Execute.$anonfun$submit$1(Execute.scala:257) [error] at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:167) [error] at sbt.CompletionService$$anon$2.call(CompletionService.scala:32) [error] at java.util.concurrent.FutureTask.run(FutureTask.java:266) [error] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [error] at java.util.concurrent.FutureTask.run(FutureTask.java:266) [error] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [error] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [error] at java.lang.Thread.run(Thread.java:748) [error] (*:update) sbt.librarymanagement.ResolveException: unresolved dependency: com.typesafe.sbteclipse#sbteclipse-plugin;2.5.0: not found Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore?
    Richard Dallaway
    @d6y
    Hi @objectamit_twitter - the project was set up long before sbt 1.0. I think what you need to do is edit or create the file project/build.properties and add (or edit) the content to be: sbt.version=0.13.16. Then sbt (or ./sbt.sh) should work for you.
    If you can try that and let me know if it helps, I’ll be able to update the project with that file.
    Amit Sharma
    @objectamit_twitter
    Hi @d6y, Sure thing. I'll do that and let you know once that completes but that still doesn't explain the dependency issue. Why is it called ensime-sbt with version 0.2.1 while the actual artifact looks like sbt-ensime with version 2.0.1?
    Richard Dallaway
    @d6y
    I guess 0.2.1 was the version we used back in 2015.
    Amit Sharma
    @objectamit_twitter
    Hmm, strangely I don't find any artifact with that name in any of the maven repos that I know of. Anyways, downgrading the set to 0.13.16 works fine and I was able to run set, compile the project and run the first example tables.Main so thank you.
    Richard Dallaway
    @d6y
    Thanks for letting me know.
    Richard Dallaway
    @d6y
    @objectamit_twitter I think I’ve found 0.2.1 for ensime-sbt. It’s published here: http://repo1.maven.org/maven2/org/ensime/ensime-sbt_2.10_0.13/0.2.1/
    Amit Sharma
    @objectamit_twitter
    Very many thanks for showing me the repository location. I'll see to it that why my sbt project does not resolve this artifact.
    Amit Sharma
    @objectamit_twitter
    Just so you know, on the video presentation, the audio is missing between 45:51 to 50:41 Is there any other link available?
    Richard Dallaway
    @d6y
    @objectamit_twitter yes, sorry about that. That was missing in the original and we’ve not been able to restore it.
    Petro Semeniuk
    @PetroSemeniuk_twitter
    hi there
    slick projection is for filtering columns, not rows. Is that correct?
    Richard Dallaway
    @d6y
    As in query.map ... yes, that is selecting columns.
    Petro Semeniuk
    @PetroSemeniuk_twitter
    thanks!