Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Gavin Bisesi
    @Daenyth
    @vn971 I believe the easiest way is to declare an implicit Isomorphism[EmailAddress, String] (which you get for free from extending MappedTo[String] in your model class if you feel that's appropriate
    Vasili Novikov
    @vn971
    @Daenyth thanks! I think that's probably it, it solved some of the problems. I still have some other left though. I'll ask later when I get an understanding of the actual story behind (or if I fix it myself).
    Gavin Bisesi
    @Daenyth
    :+1:
    Slick implicits are a pain in the ass and when the DSL just comes up with "no such method" it's obnoxious to find out how to actually fix it
    unfortunately you just have to get a feel for it
    intellij helps, a lot
    View > show implicit hints
    Vasili Novikov
    @vn971
    yeah, I often use it as well
    Dmitriy
    @dpogretskiy
    alternatively you can have 2 definitions of email like def emailString = column[String]("email") and don't bring it to *
    and use it in queries that require that
    Gavin Bisesi
    @Daenyth
    That seems anti-idiomatic to me, but it would definitely work
    Alexander Samsig
    @Asamsig
    Is it this you're looking for? slick/slick#1824
    @vn971 if you create a value class that extends mappedTo you should get all the string functions for free, since Slick 3.3 I think.
    Vasili Novikov
    @vn971
    @Asamsig my data class is not a wrapper around String, but rather a bi-directional conversion. Does mappedTo work in these cases as well?
    Alexander Samsig
    @Asamsig
    You'd have to define it as a wrapper for it to work with MappedTo. I don't have any goos examples on hand, but you can take a look at the tests in thr PR.
    Andreas Herd
    @mendrik
    is it possible to compare the LocalTime of Rep[DateTime] to a date?
    basically I would like to case datetime to time only and compare via >= to a given LocalTime
    tried created.asColumnOf[LocalTime] >= _.toLocalTime but that complains about some OptionMapper2[...] missing
    Leander Seidlitz
    @leanderseidlitz

    A question regarding the sqlite table creation:

    My table is specified as

    class FileDBItem(tag: Tag) extends Table[FileNode](tag, "Files") {
      def id = column[Int]("Id", O.AutoInc, O.PrimaryKey) 
      def path = column[String]("Path")
      def rating = column[Option[Int]]("Rating", O.Default(None))
      def views = column[Option[Int]]("Views", O.Default(None))
      def tags = column[Option[String]]("Tags", O.Default(None))
      def * = (id, path, rating, views, tags) <> ((FileNode.apply _).tupled, FileNode.unapply)
    }
    The database created as
      val files = TableQuery[FileDBItem]
      val db = Database.forURL("jdbc:sqlite:" + databaseLocation + "/" + "index.db",
        driver = "org.sqlite.JDBC",
        keepAliveConnection = true)
      val setup = DBIO.seq(
        files.schema.createIfNotExists
      )
      val setupFuture = db.run(setup)
      Await.result(setupFuture, 10.seconds)

    If the database does not exist yet and the table is therefore created, I result with

    [SQLITE_ERROR] SQL error or missing database (near "AUTO_INCREMENT": syntax error)

    As the keyword for autoincrementing is AUTOINCREMENT in sqlite, not AUTO_INCREMENT

    Is this a bug, or am I doing something wrong?
    my dependencies are
    libraryDependencies ++= Seq(
      "com.typesafe.slick"  %% "slick"                % "3.3.2",
      "com.typesafe.slick"  %% "slick-hikaricp"       % "3.3.2",
      "org.slf4j"           %  "slf4j-nop"            % "1.7.26",
      "org.xerial"          %  "sqlite-jdbc"          % "3.8.11.2"
    )
    Leander Seidlitz
    @leanderseidlitz
    I have found the error. I had imported slick.jdbc.H2Profile.api._ instead of slick.jdbc.SQLiteProfile.api._. Fixing the import resolved the issue. The H2Profile seems to be working quite well with sqlite except for creation ;)
    Andrew McKnight
    @amcknight
    Beginner here. Does anyone have an example of an open source scala project using slick with many interconnected tables that I can browse? I'm having trouble decomposing my tables. I can't seem to get away from defining all my tables and queries in one class or having to redefine my tables in many different classes. I have a workaround using an abstract class but it seems ugly.
    Gavin Bisesi
    @Daenyth
    @amcknight why do you find that?
    we have quite a large number, not open source, but all along the form of
    import blah.OurSlickProfile.api._
    
    class FooTable extends Table[Foo]("foo") {
      def id: Rep[Long] = .....
    Andrew McKnight
    @amcknight
    Sorry, I guess I should have said that I'm, having trouble separating the classes into different files.
    Gavin Bisesi
    @Daenyth
    right but why
    what is making it hard?
    Andrew McKnight
    @amcknight
    Basically, I'm curious about seeing a multi-file example with a dozen tables and a few dozen queries to see how it's organized.
    I think the thing that's making it hard is dealing with the imports. If I naively take an example with Table classes and a few queries all within a single class, then when I try to pull Tables out into their own class, I have problems wrangling the imports.
    Gavin Bisesi
    @Daenyth
    Our code usually looks something like:
    • class FooTable extends Table[Foo]
    • TableQuery[Foo] in the companion object FooTable (as .query)
    • Generic/widely applicable DBIO or Query returning functions in the companion object, taking implicit EC (find by id, for example)
    • feature specific queries in the implementation of a backend-agnostic business-semantic-focused interface, taking Database+EC as a constructor param for example)
    I don't know what imports you're having trouble with - generally we only need to import the FooProfile.api._
    we have a custom Profile class for extra mixins/implicits/compat stuff but you only need eg PostgresProfile or similar most of the time
    Andrew McKnight
    @amcknight
    Thanks for the info Gavin. I'll try some of that but I think I'm too noob and will need a full example to dig into.
    Gavin Bisesi
    @Daenyth
    Unfortunately my code is too close to company logic so I can't share it, otherwise I would.
    mvillafuertem
    @mvillafuertem

    Hi,

    Can I compile a Plain Query? I get this error

    implicitNotFound Computation of type .... cannot be compiled (as type C)

    Thanks!

    Richard Dallaway
    @d6y
    Hi @mvillafuertem - Query compilation is about taking a Slick Query and transforming it through various stages to something that is close to a SQL query. As a Plain Query is at the kind of end-stage already (a DBIO Action), compilation (in this sense) doesn't apply. Hope that's some help.
    ShankarShastri
    @shankarshastri
    Hello,
    I wanted a way to dynamically select field(column) and filter fields based on input?
    Gavin Bisesi
    @Daenyth
    dynamic filtering is a royal PITA, I'm not sure that anyone has a good solution
    We have one but it's awful and no one here likes it
    type-unsafe, tightly couples way too much from api down to db, easy to write something that doesn't do what you want
    I won't bother sharing it
    my advice for now is to flail madly and pick the first thing that lets you solve the immediate need
    it probably won't be good but I haven't seen any good approaches for this
    ShankarShastri
    @shankarshastri
    @Daenyth , can you share me the snippet for the same.
    Mohamedali10
    @Mohamedali10
    Hello , can someone explain to me how to create preparing statement with slick?
    Mohamedali10
    @Mohamedali10

    Hello I'am trying to optimize this SQL request:

     for {
          ((emp, dep),cert) <- Employees
            .filter(_.Departement === key)
            .sortBy(_.grade)
            .innerJoin(Education)
            .on(_.educationLevelPK === _.key)
            .innerJoin(Certification)
            .on(_._2.certificat === _.key)
        } yield (emp, dep, cert)

    is rendering the filter and sorting outside worth doing? and How can I make that?

    Dmitriy
    @dpogretskiy
    this request looks as optimized as it could possibly be to me, not sure what do you mean, reusing a prepared statement?