by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    kk3009
    @kk3009
    for

    ```val action =
    for {
    lock <- sql"""
    select * from anything
    """.as[Int]
    }yield (lock)

    db.run(action.filter(r => r.head > 0).andThen())
    ```

    ?
    Rakesh
    @rakeshkr00
    How to use HikariCP when creating DB connection using forURL method ? I can't find any documentation
    I was using before forConfig for the same and that by default it used to take HikariCP. However, my requirement changed recently and have to pull DB credentials from Vault. I couldn't find anyway to pull info from Vault to fed while using forConfig method.
    nafg
    @nafg
    @kk3009 something like that
    But for(x <- y) yield x, is essentially the same as y
    technically, y.map(x => x)
    Also filter on an action just fails if it's false
    Not sure what your andThen is for
    vyshnavi-adusumelli
    @vyshnavi-adusumelli

    Hi all,
    hoping to get some help. I have a column in table of type timestamp in mysql and I am trying to format it in localDateTime. The column definition in scala looks like

    val createdDate = column[LocalDateTime]("createdDate")

    It throws an exception as: java.time.format.DateTimeParseException: Text '2020-04-26 12:00:00' could not be parsed at index 10

    Richard Dallaway
    @d6y

    @vyshnavi-adusumelli Looking at the default format Slick uses for LocalDateTime in MySQL it seems to be 2020-04-26Z12:00:00.00 (possibly the .00 at the end is optional).

    If you want to customise the format Slick uses there, probably the easiest way is to wrap LocalDateTime in another class .

    10 replies
    Mohamedali10
    @Mohamedali10
    Hi, is there advantage of using MySQL over postgreSQL as a database with slick? or there is no difference?
    Antoine Doeraene
    @sherpal
    There is basically no difference. That's the promise of slick. And, in the event that you would need it, it's quite easy to define the SQL functions that would be missing from one or the other database system
    maxmc
    @splink
    Hi, I'm using postgres 11 with slick 3.x. I'd like to use plain sql to insert some data and get back the current value of the autoincrement id for the row.
    sqlu"""insert into test (greeting) values ("Hi") returning id""".map { id => ... }
    In Postgres there is the "returning" keyword which enables just that. But I couldn't figure out how to make Slick accept that an insert statement returns a value. Slick complains: "Update statements should not return a ResultSet".
    Jason Pickens
    @steinybot

    I’m having a hard time getting fold to work on an optional column. The definition is:

    /** Extension methods for Options of single- and multi-column values */
    final class AnyOptionExtensionMethods[O <: Rep[_], P](val r: O) extends AnyVal {
      /** Apply `f` to the value inside this Option, if it is non-empty, otherwise return `ifEmpty`. */
      def fold[B, BP](ifEmpty: B)(f: P => B)(implicit shape: Shape[FlatShapeLevel, B, _, BP]): BP = {
      …

    The issue is that the only value for P that seems to work is Rep[T]but then f: Rep[T] => B and there is no such function.

    Jason Pickens
    @steinybot
    For example:
    val c: Rep[Option[Long]] = b.sum
    
    // This is the implicit conversion that is always applied for c.fold:
    val d: AnyOptionExtensionMethods[Rep[Option[Long]], Rep[Long]] = anyOptionExtensionMethods(c)
    
    // This does not compile:
    val d2: AnyOptionExtensionMethods[Rep[Option[Long]], Long] = anyOptionExtensionMethods(c)
    What I want to do is:
    c.fold(0) { x =>
      if ((x) >= 0) x else 0
    }
    The comment says "Apply f to the value inside this Option, if it is non-empty, otherwise return ifEmpty” but I just can’t get f to accept the value inside the Option.
    Richard Dallaway
    @d6y
    @splink rather than sqlu"..." try sql"....".as[Long] (or similar: not tried to compile that)
    Richard Dallaway
    @d6y
    @steinybot Hello! What SQL would you want to produce? (If you're in Rep it's happening in the database, probably)
    Jason Pickens
    @steinybot
    That’s a good question. I guess it probably wouldn’t be possible. So then how is fold useful?
    Richard Dallaway
    @d6y

    I guess you can do it use SQL case expressions (to be honest, I've never really got the hang of them in SQL).

     val zero: Rep[Int] = LiteralColumn(0)
     val query: Rep[Int] = table.map(_.number).sum.fold( zero )(n => Case.If(n < 0).Then(zero).Else(n))

    That might do it. (Being very tentative... I'd want to see what that really does!)

    Luís Campos
    @LLCampos

    Hello :)

    Using Slick 3.3.2.

      case class Example1()
      case class Example2()
    
      class Table1(tag: Tag) extends Table[Example1](tag, "table1") {
        def column1 = column[String]("column1")
        def * = ???
      }
    
      private val table1 = TableQuery[Table1]
    
      class Table2(tag: Tag) extends Table[Example2](tag, "table2") {
        def column1 = column[Option[String]]("column1")
    
        def * = ???
        def requester: ForeignKeyQuery[Table1, Example1] = foreignKey("", column1, table1)(_.column1)
      }

    Shouldn't the type of requesterbe ForeignKeyQuery[Table1, Option[Example1]]since Table2's column1 is Rep[Option[String]]?

    Justin Pihony
    @JustinPihony
    Following along the lines of https://scala-slick.org/doc/3.3.2/upgrade.html#slick.jdbc.postgresprofile I'm unsure if slick.codegen.SourceCodeGenerator.run("slick.jdbc.PostgresProfile", "org.postgresql.Driver", "jdbc:postgresql://localhost/postgres", "/tmp/", "codegen", Some("postgres"), Some("password"), false, false) should generate java.time objects? It currently generates java.sql objects as I assume it's easier to go to that default. Thoughts on opening a ticket for making the generator able to spit out the java.time objects?
    Dominik Dorn
    @domdorn
    hey! the r2dbc project managed to get their postgres-driver included into the postgresql-jdbc org on github.. are there plans to support r2dbc as backend (instead of jdbc) ? they expose a publisher, but sadly use the spring project reactor underneath..
    Loránd Szakács
    @lorandszakacs
    hello folks, is there a slick WIP version for dotty?
    gomeplus
    @gomeplus
    how can i apply session parameter using slick??(without jdbc url expression) is there any example?
    Richard Dallaway
    @d6y
    Hi @gomeplus - there's a withStatementParameters on a action. That might be what you're after? It's mentioned on this page in the manual, and otherwise, there's always the source.
    Utkarsh Deep
    @utkarshdeep
    I am trying to apply join on column that is Option[Int] but as expected it is returning me nothing. How do I prohibit join if the column is None?
    gomeplus
    @gomeplus
    @d6y i've seen it before, but i wanna apply variables to specific session such as sort_buffer_size or query_buffer_size of mysql.
    Mohamedali10
    @Mohamedali10
    I'am using MySQL database with slick, I want to store the content of a file in the database in a specific encoding is there a difference to use a ByteString or Array of Bytes in order to do that? does slick use the default encoding in case of using ByteString despite I used the wanted encoding for creating the ByteString?
    Richard Dallaway
    @d6y
    @utkarshdeep maybe and a where clause to omit null columns? Something like .filter(_.column.isDefined) ?
    Richard Dallaway
    @d6y
    @gomeplus you can access the connection inside a SimpleDBIO (see, e.g., JDBC interop). Not sure if from there you can get to apply the settings you need. Failing that, the next place I'd look is on the Database object, but if you're avoiding the JDBC URL that's maybe not a route that will help.
    Ahmet Yavuz Demir
    @yavuzDemir_gitlab
    Hello folks, I have a problem that I couldn't solved
    I have a case class A where one of its fields is also Sequence of case class B
    when I try to define the table of this case class A it gives me error on "No implicit arguments of Type[Type[Seq[B]]]"
    What should I do now? :(
    André Schmidt
    @scalamat
    hello. On lagom project I create a postgres readside. But with using a composited key on each new run (tables already built) I get always a psql exception with relation already exists. My kes looks like this def idxKey = index("article_number_fulfiller_idx",(completeArticleNumber,fulfillerVendorNumber),unique = true) is their any solution for this exception?
    Justin Pihony
    @JustinPihony
    :point_up: June 21, 2020 12:06 AM If nobody responds over the weekend I'll just go ahead and create an issue - please let me know if this was intentional
    Tuomas Kinnunen
    @TK009
    Hi, what is the best way to create a Table schema with variable typed column? My software needs to create new tables with different types dynamically during runtime
    My current implementation just uses a String, but I need to use integer and float types to optimize space usage
    Roberto Leibman
    @rleibman
    What does this mean?
    Caused by: slick.SlickException: Cannot use node Filter s2 for inserting data
    in
    UserWalletQuery
              .filter(_.userId === userWallet.userId).insertOrUpdate(
                UserWallet2UserWalletRow(userWallet)
              )
    Where the table is:
      class UserWalletTable(_tableTag: Tag) extends profile.api.Table[UserWalletRow](_tableTag, Some("chuti"), "userWallet") {
        def *  = (userId, amount) <> (UserWalletRow.tupled, UserWalletRow.unapply)
        val userId: Rep[UserId] = column[UserId]("userId", O.PrimaryKey)
        val amount: Rep[BigDecimal] = column[BigDecimal]("amount")
      }
    Tuomas Kinnunen
    @TK009
    @rleibman It says that you cannot use .filter with .insertOrUpdate. I think you first need to run that select query to get a result with the primary key and then run insertOrUpdate with value having that primary key if it existed.
    Tuomas Kinnunen
    @TK009
    actually you already know the userId so you don't need to do a select query, just run insertOrUpdate without the filter
    icemanx7
    @icemanx7
    Hi guys, does anything have any guides or reading material where I can see how and what the best practices are to unit test Slick DB operations?
    Tuomas Kinnunen
    @TK009
    Maybe try to search for other projects on github and look at how others have done tests. I have just done sequential tests which create the tables and inserts some test data to an in-memory database.
    Does anyone know how ProvenShape works? I'm trying to create a table with type parameter...
    Tuomas Kinnunen
    @TK009
    ok, got it working, forgot the type parameter from apply and unapply and marked it as T: BaseTypedType