Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Paul Cleary
    @pauljamescleary
    when I tried doing this with batch, I saw individual inserts as opposed to one big insert statement that I was expecting
    فارس
    @serafdev
    Hi, do you guys have best practices for database connections?
    What I do now is I pass the (implicit session: DBSession) from the session at the main server level all the way down to the queries (so every function takes in parameter the implicit session) idk how to fix this mess
    Paul Cleary
    @pauljamescleary
    @Sindu__twitter Found out you need rewriteBatchStatements parameter to be set. Also, I was attempting to use .setBlob(new MariaDbBlob), and that was causing issues. Instead, used .setBytes(bArray) and everything worked well. Thanks!
    فارس
    @serafdev
    The problem with this is that it will start a new database session for every object, i only want to use 1 session and multiple connections in that session
    Reason for this is in my tests, when I write integration tests I need to keep multiple queries from multiple data accessors in one transaction, which is not possible if we creat a new session for each object
    Or am I wrong?
    Kazuhiro Sera
    @seratch
    @pauljamescleary Sorry for my late reply. I haven't checked here for a long time. If you need one big insert statement, you need to build such a query dynamically by your own. For instance,
    val valuesPart: SQLSyntax = sqls.csv(group.map { params => sqls"(${sqls.csv(params:_*)})" }: _*)
    sql"INSERT INTO table (a, b, c) VALUES ${valuesPart}".execute.apply()
    @Sindu__twitter It's possible to bind values from ResultSet to nested data structure. See also: http://scalikejdbc.org/documentation/one-to-x.html However, mapping to one to many to many structure by issuing a single SQL query can be inefficient for most cases. Also, you can do such mapping manually but one-to-x API doesn't support the case.
    Paul Cleary
    @pauljamescleary
    @seratch it actually does work with rewriteBatchedStatements set to true :) Verified with the general log
    Andrii Lytvynenko
    @satyriasizz

    Hi, people. I'm trying to connect ScalikeJDBC with SQLite and getting
    java.sql.SQLException: Cannot change read-only flag after establishing a connection. Use SQLiteConfig#setReadOnly and SQLiteConfig.createConnection().
    all the time.

    Is there any way to connect the lib with SQLite?

    Mark Harris
    @SiliconMeeple
    Apologies if this is a FAQ and I've just missed it somewhere. I've got a data set on S3 I'm looking to query from a lambda. The data's stored in parquet, so Athena seems like a good choice. Last time I looked, it wasn't possible to use the athena connector and scalike because it's based entirely on prepared statements, which the connector doesn't support.
    Is that still the case?
    If so, has anyone successfully used https://github.com/zaneli/scalikejdbc-athena or some other way to query Athena at a higher level than hand-rolling a lot of AWS SDK cruft?
    Jem Mawson
    @Synesso
    Hi. I'm trying to do an UPDATE ... RETURNING statement with an AutoSession, but it fails because SQLToResult enforces a readonly txn. Can I circumvent this? https://stackoverflow.com/questions/55213167/update-returning-queries-in-scalikejdbc
    Jem Mawson
    @Synesso

    Another question… I have a method that works in prod:

    DB.localTx { implicit s =>
     …
    }

    But when run in test it does not see the data set up in the fixture, as part of scalikejdbc.specs2.mutable.AutoRollback. That’s because the spec has its own transaction.
    Instead of DB.localTx, what should I use that would join the existing transaction if necessary (spec) or start a new transaction (prod)? I have access to session.tx: Option[Tx] which is Nonein prod and Some in test.

    Jem Mawson
    @Synesso
    I solved it by matching on the session type. If it’s AutoSession, I know I’m inside play. Otherwise I’m probably in a spec and need to play in the same session. This minimises the difference between prod and test code in the prod class. Not perfect, but good enough for me. Open to other suggestions:
    def statement(implicit session: DBSession): Iterator[Payment] = {
      sql"""
        update payments
        set status='submitted', submitted=$now
        where status='pending'
        and scheduled <= $now
        returning $paymentFields
      """.map(from).iterable().apply().toIterator
    }
    
    session match {
      case AutoSession => DB.localTx(statement(_))
      case _           => statement(session)
    }
    Kenneth Lu
    @krlu
    Hi all, I want to create a scala function that lets you create a table with some input name
    I have something like this def createTable(name: String): Unit = sql"""create table $name (id serial not null primary key, name varchar(64), created_at timestamp not null)""" .execute().apply()
    but if i'm understanding this right, scalike treats $name as a binding for a sql query, hence this doesn't work
    any suggestions ?
    Vladimir Morozov
    @greenhost87
    Hi all, how to correct read and write Seq[T] stored as JSONB in PostrgeSQL?
    Jonas Natten
    @jnatten
    This isn't really a scalikejdbc issue, but I'm using json4s to serialize and deserialize data to jsonb. And after upgrading json4s from 3.5.5 to 3.6.x something goes wrong.
    I just use read[LearningPath](jsonString) in my constructor to deserialize and the LearningPath type is defined like this: http://scalikejdbc.org/documentation/one-to-x.html
    stacktrace -> https://hastebin.com/naxadomano.scala
    Any suggestions?
    larstoc
    @larstoc

    Hey, I was wondering how I would call a stored procedure with scalike.

    CREATE OR REPLACE FUNCTION truncate_tables() RETURNS void AS $$
    DECLARE
        statements CURSOR FOR
            SELECT tablename FROM pg_tables
            WHERE schemaname = 'public';
    BEGIN
        FOR stmt IN statements LOOP
            EXECUTE 'TRUNCATE TABLE ' || quote_ident(stmt.tablename) || ' CASCADE;';
        END LOOP;
    END;
    $$ LANGUAGE plpgsql;

    This is the stored procedure I'm using. I was hoping I could do something like this:

    val sql = sqls"select truncate_tables()"
    sql.single.apply()

    Is there a way to do this?

    larstoc
    @larstoc
    No one watching this channel anymore?
    Kenneth Lu
    @krlu
    @larstoc so, I'm not a contributor to scalike, but I think the best way to get your question answered might be to post a github issue:
    amirhac
    @amirhac
    Hello, is anyone use scalikejdbcGen with Presto? When I tried it, I am getting java.sql.SQLFeatureNotSupportedException: primary keys not supported Exception since primary keys is not supported in Presto jdbc library.
    uneewk
    @uneewk
    Hello, also interested in knowing if anyone here has used ScalikeJDBC with AWS Snowflake. I pretty much have it working for Inserts/Deletes but Select statements fail because it appears ScalikeJDBC is using readOnly DB session and attempting to set the readOnly flag on the underlying JDBC driver which is failing in snowflake-jdbc because setting the flag is not supported. Has anyone run into this before or know a workaround?
    uneewk
    @uneewk
    Perhaps lemme ask question in a different way: can a run a select query via ScalikeJDBC query interpolation in a non-readonly way?
    Kazuhiro Sera
    @seratch
    @larstoc Thanks for submitting an issue - as I already answered there, it's not supported yet scalikejdbc/scalikejdbc#1062
    @amirhac hmm, I've never tried to run the command with Presto. If fixing the incompatibility needs a little efforts, it may be possible to address it.
    @uneewk will respond to your GH issue later
    hanchi321
    @hanchi321
    Hello, is anyone read Typesafe Config from HDFS path? For different Environment using different config path
    Han Ju
    @darkjh
    Hi. Just found out that when I'm using sql interpolation with java.time.LocalDateTime, scalikejdbc acutally changes the time according to the default time zone. Is there a way to deactivate this behavior? Thanks!
    What we want is just to write the LocalDateTime as is into DB, regardless of the timezone on the machine.
    2 replies
    Ilya Kachalsky
    @IlyaHalsky
    Hi everyone, does anyone know where to find change log for new versions?
    Dragutin Marjanović
    @drmarjanovic

    Hi,

    Is there an option to use .returning in update when where is mixed in. I've found an example in the tests but there's no .where there.

    https://github.com/scalikejdbc/scalikejdbc/pull/564/files#diff-38bdbca7a63805a821b4dfed41ddb2b2R664

    But, when I try something like:

    update(A).set(ac.name -> "value").where.eq(ac.id, 1).returning(ac.*)

    it doesn't work.

    I found a workaround and use .append(sqls"returning ${ac.*}).

    I would create a PR for this if currently there's no way to do it.

    Please let me know. Thanks in advance.

    Roberto Leibman
    @rleibman
    Hello! So... I'm working on this gnarly query that has a bunch of CTEs... I need to construct my query dynamically, and inside the dynamic part there's variables... paraphrasing my real query:
      val strings = List("A", "B", "C")
      val queryStr = s"""WITH cte AS (${strings.map(s => s"select '${s}' as MyCol").mkString(" UNION ALL ")}) select * from cte"""

    I then do:

    SQL(queryStr)

    In order to get a scalalikejdbc query that I can use.

    But this is open to a sql injection!
    How would you handle this?
    Przemek Sokół
    @falconepl
    Hi there! I've been wondering whether it is possible to build SQL queries with ScalikeJDBC without connecting to the database and without side effects. I guess that ScalikeJDBC can connect to DB to figure out table syntax. That's cool but I would rather provide table definition myself (as in Slick), even if the query is going to fail at runtime (due to misspelled column name etc.). I simply want to get rid of SQL query strings in my codebase in favor of ScalikeJDBC DSL. Is it doable or is valid connection pool in ScalikeJDBC absolutely necessary for it to operate (to construct SQL query strings)?
    Ilya Kachalsky
    @IlyaHalsky

    @rleibman

    How would you handle this?

    I'm doing so using SQLSyntax,

      val strings = List("A", "B", "C")
      val queryStr = sqls"""WITH cte AS (${strings.map(s => s"select ${s} as MyCol").mkString(" UNION ALL ")}) select * from cte"""
    And then you can simply do sql"${queryStr}"
    I also have a question:
    Is there a way to register out parameters for queries like {? = call function(?)}
    jahan01
    @jahan01
    Hello, Just started to play around with this awesome library today. I have some questions. Are the real connection to DB is lazily established? If yes, is there a way see when actual connection is established ?
    jahan01
    @jahan01
    Also is there a way to see which connection from the pool was used to run a query ?
    jahan01
    @jahan01
    Hello, I would like have access to statement (or prepared statement) object before it is closed. I believe it is encapsulated in StatementExecutor case class. Is it possible get access to StatementExecutor object ?
    Matt Dziuban
    @mrdziuban
    hi all, I'm seeing that if I run multiple queries in parallel using withinTx, all of the queries take as long as the longest one, however if I use AutoSession then the queries complete as quickly as they finish executing. is this expected behavior?
    Anu Zachariah
    @anuzach7_twitter
    Hi, How can I increase the maxPoolSize and maxQueueSize of the AsyncConnectionPool. I keep getting the queue is full error.