by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    nova
    @nova999
    What should I do?
    Gavin Bisesi
    @Daenyth
    I'm guessing that it might be related to the fact that sbt does not trigger application shutdown hooks when you run something (unless you've configured some stuff)
    if you do the two commands in separate sbt sessions, it should work, or settings fork := true for one or another of the scopes you're trying to do
    nova
    @nova999
    I haven't changed or added any drastic configurations, but just in case I tried out the vanilla template straight from the git repo and it has the same problem.
    Doing sbt run directly doesn't seem to fix it either.
    pratik-brex
    @pratik-brex
    are there examples of slick with embedded postgres? i have a postgres profile that reads from a typesafe config but for my tests i'd like to pass an EmbeddedPostgres into the profile. how do i go about doing that?
    Gavin Bisesi
    @Daenyth
    Why does the profile read from config?
    I'd expect your app to read the config, then construct using something like Database.forConfig where Database is imported from the profile
    pratik-brex
    @pratik-brex
    i figured it out; i used Database.forDataSource and passed in the resulting DataSource that embedded PG returned
    Heikki Vesalainen
    @hvesalai
    @pratik-brex re your issue on github, check the signature of += from scaladoc first and see that you have the required implicits and implicit extension methods imported where you are trying to call +=
    pratik-brex
    @pratik-brex
    @hvesalai hm, which implicits maybe missing? i'm importing profile.api._
    Heikki Vesalainen
    @hvesalai
    Some implicit extension method is missing or += is protected. Methods don't disappear in scala when you extend things.
    pratik-brex
    @pratik-brex
    ah you're right; it's missing the api implicit
    František Kocun
    @fokot
    hi guys, any idea how to generate one insert which selects from one table and insert to another. this is what i'm trying. problem is how to change brandTable.map(b => (b.name, 2020.bind)) resultsing tuple to Car. it does not compile
      case class Car(brand: String, year: Int)
      class CarTable(tag: Tag) extends Table[Car](tag, "car") {
        def * : ProvenShape[Car] = (brand, year) <> (Car.tupled, Car.unapply)
        val brand: Rep[String] = column[String]("brand")
        val year: Rep[Int] = column[Int]("year")
      }
      val carTable: TableQuery[CarTable] = TableQuery[CarTable]
    
      case class Brand(id: Long, name: String)
      class BrandTable(tag: Tag) extends Table[Brand](tag, "brand") {
        def * : ProvenShape[Brand] = (id, name) <> (Brand.tupled, Brand.unapply)
        val id: Rep[Long] = column[Long]("id")
        val name: Rep[String] = column[String]("name")
      }
      val brandTable: TableQuery[BrandTable] = TableQuery[BrandTable]
    
    
    //  val carQuery: Query[BrandTable, Car, Seq] = ???
      val carQuery: Query[BrandTable, Car, Seq] =
        brandTable.map(b => (b.name, 2020.bind))
      carTable.forceInsertQuery(carQuery)
    František Kocun
    @fokot
    i found solution with naming all columns. but in my real issue (this is jsut example) i have 20 columns, so i would like to avoid it
      val carQuery =
        brandTable.map(b => (b.name, 2020.bind))
      carTable.map(c => (c.brand, c.year)).forceInsertQuery(carQuery)
    Laszlo Konya
    @lkonya
    Hi! How would you test if a user supplied query has the necessary privileges to run? The query is supplied runtime by the user. I was thinking to use sql"explain #$query" but what would be the result type?
    Laszlo Konya
    @lkonya
    I don't need the result. Only if the query was successful or not.
    Gavin Bisesi
    @Daenyth
    I have to say it even if you know, but that code snippet is 100% raw unfiltered sql injection. I can give you a query of "select 1; select email, password from users" etc
    or maybe a delete from users, since there's no output. There's also probably a way to run a statement that does nefarious things with the server's scripting support
    nova
    @nova999
    obligatory - https://xkcd.com/327/
    Gavin Bisesi
    @Daenyth
    It's extremely unlikely you will be able to improve your project quality by mocking slick
    Mock your high-level service interfaces (that don't mention databases in them), and test your database implementations using the same database you run in production

    as for how to make it work - no clue at all. But I will say that it's likely to cause you exceptional amounts of pain to even try, having seen slick's internals. And the end result of those tests will be brittle and coupled intimately to implementation details.

    In every case I've seen of people mocking the database in any language with any tool, the resulting tests:

    • Broke when implementations refactored, even if the real behavior worked
    • Passed even when the real behavior was broken
    tldr: run the damn sql :p
    Abel Terefe
    @AbelBTerefe_twitter

    Hi, I was testing Scala 2.13.2 with Slick 3.3.2 and I keep getting the following error when running migrations with flyway-sbt plugin.

    [http-module] $ core/flywayMigrate
    [info] Migrating schema "public" to version 1 - Create all tables
    [error] java.lang.NoSuchMethodError: scala.runtime.ScalaRunTime$.wrapRefArray([Ljava/lang/Object;)Lscala/collection/immutable/ArraySeq;
    [error]         at slick.relational.RelationalCapabilities$.<clinit>(RelationalCapabilities.scala:59)
    [error]         at slick.relational.RelationalProfile.computeCapabilities(RelationalProfile.scala:25)
    [error]         at slick.relational.RelationalProfile.computeCapabilities$(RelationalProfile.scala:25)
    [error]         at com.msard.core.util.CustomPostgresDriver$.slick$sql$SqlProfile$$super$computeCapabilities(CustomPostgresDriver.scala:95)

    I have tried sbt clean, cleanFiles, cleanKeepFiles, to no avail.

    nova
    @nova999
    Do you get the same error with 2.13.1?
    Abel Terefe
    @AbelBTerefe_twitter
    Yes, but Scala 2.12.x works fine.
    nafg
    @nafg
    @AbelBTerefe_twitter how is flyway-sbt calling into slick?
    Abel Terefe
    @AbelBTerefe_twitter
    @nafg Table.schema.createStatements.map(connection.prepareStatement).foreach(_.execute) in a flyway-versioned V1__Create.scala
    nafg
    @nafg
    @AbelBTerefe_twitter hmm I think what's happening is that the way flyway-sbt works, is that it gets sbt to compile your code the way sbt would, but then it's instantiating Flyway from the SBT classpath, which has scala 2.12, and configuring it with your project classpath as a resolver (which include 2.13)
    Perhaps ditch flyway-sbt and just use Flyway from your own code
    You could make a separate subproject if you prefer. In any case you could make your own main class that does whatever flyway tasks you use
    Abel Terefe
    @AbelBTerefe_twitter
    @nafg Thanks! I’ll try that
    nafg
    @nafg
    Once Flyway is on a project's classpath you could also interact with it via console
    For instance, you could have an object MyFlyway { val flyway = ... } and in sbt set mysubproject / console / intialCommands := "import MyFlyway.flyway"
    then you could do
    > console
    scala> flyway.migrate()
    etc.
    Jyoti Sachdeva
    @jyotisachdeva57_gitlab

    I want to call the procedure tht has five params:
    so i have created the function as

     def five[T1, T2, T3,T4,T5, R : TypedType](fname: String, fn: Boolean = false): ((Rep[T1], Rep[T2], Rep[T3],Rep[T4],Rep[T5]) => Rep[R]) = {
        val f = SimpleFunction.apply(fname, fn);
        { (t1: Rep[T1], t2: Rep[T2], t3: Rep[T3],t4:Rep[T4],t5:Rep[T5]) => f(Seq(t1, t2, t3,t4,t5)) }
      }

    My sql procedure function returns TABLE(res1 String, res2 String)

    case class CaseClass(res1: String,res2: String)

    Now i am calling my method:

    val f =  five[String,String,String,String,String,CaseClass]("function")

    How can i cast the TABLE(res1 String, res2 String) to CaseClass

    I have tried:

     implicit val caseClass = CaseClass(r.nextString(), r.nextString())

    It did not work for me.

    nova
    @nova999
    The only way I know would be f.map(e => (e.field1, e.field2).mapTo[MyCaseClass])
    Jyoti Sachdeva
    @jyotisachdeva57_gitlab

    @nova999
    What would be the result type in

    val f =  five[String,String,String,String,String,CaseClass]("function")

    as writing CaseClass gives error, that no implicit found.
    And i the map function that you mentioned is not available on f.

    nova
    @nova999
    Right, that method only works on the table type directly. For example -
    case class TextOnly(id: Long, content: String)
    
    val contentQuery = messages.
      map(t => (t.id, t.content).mapTo[TextOnly])
    You could create the case class instance the normal way after calling result - MyCaseClass(field1, field2) . If you want to do it implicitly then I don't know.
    Amit Prasad
    @amitprasad01_twitter
    Hi Everyone ,
    I am using slick 3.2.1
    InsertOrUpdate is not supported on a table without PK error getting while updating a table
    Is it compulsory in slick to make PK to update or insert ?
    nafg
    @nafg
    You want to insert, or to update, or to do an insertOrUpdate?
    Matt Oliver
    @halfmatthalfcat
    Does calling Database.forConfig multiple times in an application spin off multiple connection (pools) or does Slick cache the created database on subsequent calls?
    for instance, if I have actors trying to make db calls and getting a reference to the db, are they each individually spinning up separate pools or are they (depending on what node they're on in a clustered environment) pulling from the local pool?
    Arkankhan Pathan
    @arkankhan-ak
    Hello I am new to slick and I want to learn transaction in slick, can anyone provide me resource? Thank You in advance !
    Richard Dallaway
    @d6y

    Hello @arkankhan-ak and welcome :wave: The Slick Manual has a section on transactions, and there's Essential Slick which is a tutorial introduction to Slick, which has a section on transactions too.

    The basic idea is: combine actions into a single action, and stick .transactionally on the end :+1:

    Arkankhan Pathan
    @arkankhan-ak
    thank you @d6y !