by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    nafg
    @nafg
    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.

    Rohan Sircar
    @rohan-sircar
    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.

    Rohan Sircar
    @rohan-sircar
    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 !
    Amit Prasad
    @amitprasad01_twitter
    Hi everyone
    While i am inserting Option[String] in slick table it is inserting data with double quotes
    Can someone please help me what i might be missing here
    example Option[String] = Some("slick") then in table "slick"
    with both the quotes
    Antoine Doeraene
    @sherpal
    what's your table definition ?
    Amit Prasad
    @amitprasad01_twitter
    def externalId: Rep[Option[String]] = column[Option[String]](EXTERNAL_ID)
    this is the one
    and entity externalId: Option[String] = None
    amantuer
    @amantuer
    Hi everyone, I'm new to slick. I goy this error when adding slick to playframework(scala)..
    //this is error below:
    value PrimaryKey is not a member of Int
    //from this line below:
    def id = column[Int]("id",0.PrimaryKey,0.AutoInc) 
    //and this is build file below:
    
    lazy val root = (project in file(".")).enablePlugins(PlayScala)
    
    scalaVersion := "2.13.0"
    
    libraryDependencies += guice
    libraryDependencies += "org.scalatestplus.play" %% "scalatestplus-play" % "5.0.0" % Test
    
    
    libraryDependencies ++= Seq(
      "mysql" % "mysql-connector-java" % "8.0.19"
    )
    
    libraryDependencies ++= Seq(
      "com.typesafe.play" %% "play-slick" % "5.0.0",
      "com.typesafe.play" %% "play-slick-evolutions" % "5.0.0"
    )
    //and this is code below:
    package models
    
    import javax.inject.{Inject,Singleton}
    import play.api.db.slick.DatabaseConfigProvider
    import slick.jdbc.JdbcProfile
    
    import scala.concurrent.{Future,ExecutionContext}
    
    @Singleton
    class PersonRepository @Inject()(dbConfigProvider: DatabaseConfigProvider)(implicit ec: ExecutionContext){
        private val dbConfig = dbConfigProvider.get[JdbcProfile]
    
        import dbConfig._
        import profile.api._
    
        private class PeopleTable(tag:Tag) extends Table[Person](tag,"people"){
    
           def id = column[Int]("id",0.PrimaryKey,0.AutoInc)
           def name = column[String]("name")
           def mail = column[String]("mail")
           def tel = column[String]("tel")
    
           def * = (id,name,mail,tel)<>((Person.apply _).tupled,Person.unapply)
    
        }
    
        private val people = TableQuery[PeopleTable]
    
        def list(): Future[Seq[Person]] = db.run{
            people.result
        }
    }
    Tim Moore
    @TimMoore
    @amantuer that should be the letter "O" as in "option" for O.PrimaryKey and O.AutoInc, not the number zero.
    amantuer
    @amantuer
    @TimMoore Thanks, that helped..
    amantuer
    @amantuer
    Hello me again, got an error "CreationException: Unable to create injector, see the following errors:"
    //this is error below:
    1) No implementation for play.api.db.slick.DatabaseConfigProvider was bound.
      while locating play.api.db.slick.DatabaseConfigProvider
        for the 1st parameter of models.PersonRepository.<init>(PersonRepository.scala:34)
      while locating models.PersonRepository
        for the 1st parameter of controllers.HomeController.<init>(HomeController.scala:18)
      while locating controllers.HomeController
        for the 2nd parameter of router.Routes.<init>(Routes.scala:29)
      at play.api.inject.RoutesProvider$.bindingsFromConfiguration(BuiltinModule.scala:137):
    Binding(class router.Routes to self) (via modules: com.google.inject.util.Modules$OverrideModule -> play.api.inject.guice.GuiceableModuleConversions$$anon$4)
    
    1 error
    
    No source available, here is the exception stack trace:
    ->com.google.inject.CreationException: Unable to create injector, see the following errors:
         com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:543)
         com.google.inject.internal.InternalInjectorCreator.initializeStatically(InternalInjectorCreator.java:159)
         com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:106)
         com.google.inject.Guice.createInjector(Guice.java:87)
         com.google.inject.Guice.createInjector(Guice.java:78)
         play.api.inject.guice.GuiceBuilder.injector(GuiceInjectorBuilder.scala:200)
         play.api.inject.guice.GuiceApplicationBuilder.build(GuiceApplicationBuilder.scala:155)
         play.api.inject.guice.GuiceApplicationLoader.load(GuiceApplicationLoader.scala:21)
         play.core.server.DevServerStart$$anon$1.$anonfun$reload$3(DevServerStart.scala:189)
         play.utils.Threads$.withContextClassLoader(Threads.scala:21)
         play.core.server.DevServerStart$$anon$1.reload(DevServerStart.scala:181)
         play.core.server.DevServerStart$$anon$1.get(DevServerStart.scala:141)
         play.core.server.AkkaHttpServer.handleRequest(AkkaHttpServer.scala:296)
         play.core.server.AkkaHttpServer.$anonfun$createServerBinding$1(AkkaHttpServer.scala:186)
         akka.stream.impl.fusing.MapAsync$$anon$30.onPush(Ops.scala:1261)
         akka.stream.impl.fusing.GraphInterpreter.processPush(GraphInterpreter.scala:541)
         akka.stream.impl.fusing.GraphInterpreter.execute(GraphInterpreter.scala:423)
         akka.stream.impl.fusing.GraphInterpreterShell.runBatch(ActorGraphInterpreter.scala:624)
         akka.stream.impl.fusing.GraphInterpreterShell$AsyncInput.execute(ActorGraphInterpreter.scala:501)
         akka.stream.impl.fusing.GraphInterpreterShell.processEvent(ActorGraphInterpreter.scala:599)
         akka.stream.impl.fusing.ActorGraphInterpreter.akka$stream$impl$fusing$ActorGraphInterpreter$$processEvent(ActorGraphInterpreter.scala:768)
         akka.stream.impl.fusing.ActorGraphInterpreter$$anonfun$receive$1.applyOrElse(ActorGraphInterpreter.scala:783)
         akka.actor.Actor.aroundReceive(Actor.scala:533)
         akka.actor.Actor.aroundReceive$(Actor.scala:531)
         akka.stream.impl.fusing.ActorGraphInterpreter.aroundReceive(ActorGraphInterpreter.scala:690)
         akka.actor.ActorCell.receiveMessage(ActorCell.scala:573)
         akka.actor.ActorCell.invoke(ActorCell.scala:543)
         akka.dispatch.Mailbox.processMailbox(Mailbox.scala:269)
         akka.dispatch.Mailbox.run(Mailbox.scala:23
    // this is  PersonRepository.scala file below:
    package models
    
    import javax.inject.{Inject,Singleton}
    import play.api.db.slick.DatabaseConfigProvider
    import slick.jdbc.JdbcProfile
    
    import scala.concurrent.{Future,ExecutionContext}
    
    
    @Singleton
    class PersonRepository @Inject()(dbConfigProvider: DatabaseConfigProvider)(implicit ec: ExecutionContext){
        private val dbConfig = dbConfigProvider.get[JdbcProfile]
    
        import dbConfig._
        import profile.api._
        import Person._
    
        private class PeopleTable(tag:Tag) extends Table[Person](tag,"people"){
    
           def id = column[Int]("id",O.PrimaryKey,O.AutoInc)
           def name = column[String]("name")
           def mail = column[String]("mail")
           def tel = column[String]("tel")
    
           def * = (id,name,mail,tel)<>((Person.apply _).tupled,Person.unapply)
    
        }
    
        private val people = TableQuery[PeopleTable]
    
        def list(): Future[Seq[Person]] = db.run{
            people.result
        }
    }
    //this is HomeController.scala file:
    package controllers
    
    import models._
    import javax.inject._
    
    
    import play.api.data.Form
    import play.api.data.Forms._
    import play.api.data.validation.Constraints._
    import play.api.i18n._
    import play.api.libs.json.Json
    import play.api.mvc._
    import scala.concurrent.{ExecutionContext,Future}
    
    
    
    @Singleton
    class HomeController @Inject()(repository:PersonRepository,cc:MessagesControllerComponents)(implicit ec: ExecutionContext)extends MessagesAbstractController(cc){
    
         def index() = Action.async{ implicit request =>
           repository.list().map{ people =>
              Ok(views.html.index("People Data.",people))
    
           }
    
         }
    
    }
    Antoine Doeraene
    @sherpal
    what does your database configuration look like in the application.conf file?
    Richard Dallaway
    @d6y

    Hi everyone
    While i am inserting Option[String] in slick table it is inserting data with double quotes

    Hi @amitprasad01_twitter - I'd check you have the right profile imported for the database you're using. E.g., import slick.jdbc.OracleProfile.api._ for ORACLE, or import slick.jdbc.H2Profile.api._ for H2 etc. That would possibly impact the SQL that's being generated. If that's not it, give us an example of a query to see if we can see anything troubling there.

    amantuer
    @amantuer
    @sherpal hi there, here is application.conf file.
    # https://www.playframework.com/documentation/latest/Configuration
    
    db = {
      driver = "ccom.mysql.jdbc.Driverr",
      url = "jdbc:mysql://localhost:3306/lib",
      user = "root",
      password = "12345678",
      connectionPool = disabled
    }
    Antoine Doeraene
    @sherpal

    ccom.mysql.jdbc.Driverr -> this looks suspicious (it should probably be com.mysql.jdbc.Driver). Alos, for usage with play, unless you changed something, you want your db object configuration in slick.dbs.default, like so:

    slick.dbs.default {
      db = {
        url = "jdbc:mysql://localhost:3306/lib"
        user = "root"
        password = "12345678"
        driver = "com.mysql.jdbc.Driver"
      }
      profile = "slick.jdbc.SQLServerProfile$"
      numThreads = 10 # or whatever
    }

    (not 100% certain about the profile, never used mysql, but within your ide you can type slick.jdbc.[...] and you should see the complete list of possible profiles).
    Note that the "default" in the conf is just a convention, you could have several databases with different names. There are used for migration (name of migration folder should match that) and for DI within the controllers, for example

    Georgii Kovalev
    @kovalyovGA
    Hey, is it possible to check option equality like this or should I match on xOpt ?
    table.filter(_.xOpt === xOpt.bind)
    Richard Dallaway
    @d6y

    @kovalyovGA what you have there will evaluate into SQL along the lines of where xOpt = the-value-of-right-hand-side (if it's a Some) and where xOpt = NULL (if it's None). The second case is false, which may be what you want to happen.

    If you need to be explicit about NULL handling, you'll be using isEmpty (IS NULL) or isDefined (IS NOT NULL)

    Georgii Kovalev
    @kovalyovGA
    @d6y thanks, thought it might be special === sign for option.
    Bob Lewis
    @scruffycatherder

    Hi, I'm working with slick for the first time, and seeing some sub-optimal behavior that doesn’t seem to match the docs.
    This code

    dbConfig.db.run(table.filter(_.id === id).filter(_.active === true).result.headOption)

    should generate sql along the lines of

    select * from TRAVEL_BOOKING_AGENT_INFO where id = $id and active = $active"

    But what I’m seeing in the logs is this:

    2020-06-01 13:22:40 DEBUG slick.jdbc.JdbcBackend.statement  Preparing statement: select `id`, `travel_booking_id`, `assigned_agent_id`, `assigned_agent_name`, `active`, `create_date` from `TRAVEL_BOOKING_AGENT_INFO`

    Instead of using a WHERE clause, it is pulling the entire table and post filtering.

    Bob Lewis
    @scruffycatherder
    It seems that this is only happening when we use the MySQL driver. In our unit test environment we are using H2, and it is properly generating where clauses there.
    Has anyone seen this before? Any idea how to fix it?
    Richard Dallaway
    @d6y

    @scruffycatherder I've not seen anything like that before. Looks to me like it should be OK. I've checked a project I have, and the generated SQL from something like that query is as we expect it.

    Always worth checking you have the right profiles imported for each environment (H2 and MySQL), but I doubt that's it.

    Perhaps as a sanity check re-work what you have as something equivalent to this...

    val action = messages.filter(_.id === id).filter(_.active === true).result.headOption
    println(query.statements.mkString)
    dbConfig.db.run(action)

    ...which would at least tell you that action is what you expect. In case there's some confusion in the logging or the way the action is being run.

    Bob Lewis
    @scruffycatherder
    I'm sorry, please ignore. This was a complete red herring. UTS error.
    JeansHH
    @JeansHH
    Hi, the default AsynExecutor has 20 threads and Int.max connections. This produces s compiler warning for possible deadlocks. Is this intended? Should I replace the default AsyncExecutorß
    1 reply
    Vasileios Lampridis
    @V-Lamp
    Hi, when inserting multiple rows (++=), Redshift does one insert per row, which esp. for Redshift is quite problematic. Is there some setting or way to intervene on slick in order to do batch insert? Many thanks
    kk3009
    @kk3009
    @nafg any idea on how we can combine stored procedures in ms-sql like Sp_getapplock @Resource ='keyname', @LockMode='Exclusive' with other slick queries to create a recipe so that I can acquire this lock and execute other queries in a single transaction? thanks
    nafg
    @nafg
    @kk3009 why don't you use the sql or sqlu string interpolator