https://kotlinlang.org logo
Join SlackCommunities
Powered by
# komapper
  • d

    dave08

    08/14/2024, 10:25 AM
    It seems like `DryRunResult`'s
    sql
    property doesn't give me a regular sql statement with `?`s and I'd suppose that the
    args
    don't give me what to bind for all the
    ?
    , but rather some format Komapper uses... is there some kind of api that does give me an sql with all the
    ?
    and all the params to bind with (even if they're repeated in the statement...). I need to make a temporary compat layer with Jasync, and I would like to use it's prepared statements until I have the time to fully migrate.
  • t

    Toshihiro Nakamura

    08/14/2024, 10:43 AM
    The
    sql
    property of
    DryRunResult
    does include
    ?
    . If the
    sql
    property does not contain all the
    ?
    placeholders that would actually be issued, it might be because the dry run is not using the correct database configuration. You can easily retrieve all the values to be bound as well. Please try the following code.
    Copy code
    val query = QueryDsl.insert(a).single(Address(street = "street A"))
    val result = query.dryRun(db.config) // or `db.dryRunQuery(query)`
    // sql with all the ?
    val sql = result.sql
    // all the params to bind with the sql
    val allArgs = result.args.map { it.any }
    d
    • 2
    • 11
  • d

    dave08

    08/15/2024, 12:59 PM
    @Toshihiro Nakamura Is the projection api implemented in a way that I could easily adapt it for my Jasync compat layer? Or does it really depend too much on running requests using Komapper?
    t
    • 2
    • 4
  • t

    Toshihiro Nakamura

    08/17/2024, 2:12 AM
    Hello everyone, We’re pleased to announce the release of Komapper v2.2.0. The key feature in this update is the compile-time validation of SQL templates and their parameters, which enhances the safety and reliability of your code. For more details, please refer to the release notes. https://github.com/komapper/komapper/releases/tag/v2.2.0
    🎉 3
  • d

    dave08

    09/11/2024, 10:01 AM
    @Toshihiro Nakamura How could I write these in QueryDsl:
    Copy code
    select...
                        ((FLOOR(RANDOM() * (100 - 0 + 1)) + 5)::BIGINT) AS random,
                        (OTHER.tags_token::INT[] & ?::INT[]) AS similarity
    from ...
    t
    • 2
    • 15
  • d

    dave08

    09/11/2024, 4:04 PM
    Another little question... if I have a long field declaration (like a subquery) in my select statement and I want to order by it, it seems like Komapper copies the whole statement over into the order by produced (tested using dryRun)... is there any way to force-assign an
    AS foo
    to the field in select that it should use that in the order by?
    t
    • 2
    • 16
  • t

    Toshihiro Nakamura

    09/16/2024, 12:13 AM
    Hello everyone! 🎉 We’re excited to announce the release of Komapper v3.0.0! 🚀 This major update introduces a key improvement to SQL Partial functionality: • The
    KomapperPartial
    annotation is now applied to classes, and these classes are passed as parameters to commands, streamlining how SQL templates reference partials. For more details on this and other changes, check out the release notes: 👉 https://github.com/komapper/komapper/releases/tag/v3.0.0 We’re excited to see how you’ll use this new feature! 🙌
    🎉 4
    d
    • 2
    • 1
  • d

    dave08

    09/17/2024, 11:30 AM
    > Unlike other variable directives, they do not require test data immediately after the directive. In embedded variable directives docs, it sounds like it's possible to put test data there (which could be useful, like including test table names when using it for table names in FROM -- when keeping the sql runnable), but that doesn't really work...
    t
    • 2
    • 4
  • d

    dave08

    09/17/2024, 11:34 AM
    Also, empty WHEREs etc... are removed, that might be nice to do for stray commas in for loops... (like:
    ORDER BY name, address,
    ) instead of having to use the more verbose _`_has_next` test)_
    t
    • 2
    • 4
  • t

    Toshihiro Nakamura

    10/06/2024, 12:03 AM
    Hello everyone! We’ve just released Komapper v3.1.0! This version brings two main improvements for SQL templates: 1. Added special variables in the
    for
    directive to simplify code. 2. Improved error messages to better indicate where issues occur in SQL. https://github.com/komapper/komapper/releases/tag/v3.1.0
    👍🏼 1
    👍 1
    d
    • 2
    • 4
  • d

    dave08

    10/09/2024, 9:34 AM
    @Toshihiro Nakamura I was wondering if I could re-use a Command for different results by declaring it Exec and mapping it myself after running the dryRun query with Jasync, or is Exec parsed differently in way that wouldn't accept regular select statements?
    t
    • 2
    • 1
  • d

    dave08

    10/09/2024, 9:35 AM
    I could always use Many and then just make a dummy mapper that maps to nothing, but is that really necessary?
  • d

    dave08

    10/10/2024, 11:43 AM
    Little idea, I've seen templating languages that either ignore whitespace or not depending on how the directives are declared (like
    /*-
    for removing whitespace before the directive), this could be useful when declaring more complex
    @KomapperCommands
    , keeping normal formatting for the sql while still staying within the editor's bounderies (not having to scroll horizontally too much...), what do you think @Toshihiro Nakamura?
    t
    • 2
    • 4
  • d

    dave08

    10/10/2024, 12:00 PM
    Another nice thing would be to have a
    @KomapperProjectionDef
    for when the model is declared in another module that shouldn't have a dependency to Komapper...
    t
    • 2
    • 10
  • d

    dave08

    10/10/2024, 1:27 PM
    @Toshihiro Nakamura I have my JasyncDatabase implementation for running Commands, but I see I need to implement another method for projections... what's the simplest way to do it (I posted the current code in the thread)?
    t
    • 2
    • 8
  • d

    dave08

    10/29/2024, 9:04 AM
    @Toshihiro Nakamura It'd be nice to have a template function
    List.size()
    ... or maybe I can just use the property on the list straight from the
    List<Int>
    parameter in the KomapperCommand? If so, why are there all those functions on CharSequence and String? It seems like I'm not getting any compile errors when using
    /* listParam.size */
    so does that mean it works?
    t
    • 2
    • 3
  • d

    dave08

    10/29/2024, 9:11 AM
    Also, maybe there should be a check for stray
    ?
    in KomapperCommands(/templates?), they don't seem to make sense... and one might forget a few when migrating queries to templates.
    t
    • 2
    • 11
  • d

    dave08

    10/29/2024, 9:13 AM
    Lastly, how would a List<Int> parameter in a KomapperCommand be rendered in
    unnest(/*listParam*/::int[])
    ?
    t
    • 2
    • 25
  • t

    Toshihiro Nakamura

    11/16/2024, 5:12 AM
    Hello everyone! Komapper v4.0.0 has been released! 🎉 https://github.com/komapper/komapper/releases/tag/v4.0.0
    🎉 3
  • t

    Toshihiro Nakamura

    11/28/2024, 11:08 PM
    Currently, Komapper does not work with Kotlin 2.1, but a compatible version is scheduled for release this weekend.
    👍🏼 1
  • t

    Toshihiro Nakamura

    11/29/2024, 11:55 PM
    Hey everyone! We just released Komapper v5.0.0! 🎉 This update brings improvements to the Spring Boot auto-configuration features and adds support for Kotlin v2.1.0. Be sure to check out the release notes and the migration guide for all the details. https://github.com/komapper/komapper/releases/tag/v5.0.0
    🎉 2
  • t

    Toshihiro Nakamura

    01/19/2025, 3:25 AM
    Hello everyone, We’re excited to announce the release of Komapper 5.1.0! This version introduces support for collecting SQL execution statistics, a Spring Boot test slice feature, and more. https://github.com/komapper/komapper/releases/tag/v5.1.0
    🙌 1
  • t

    Toshihiro Nakamura

    02/09/2025, 1:57 AM
    Hello everyone, We have released Komapper 5.2.0. This release includes enhanced support for Quarkus and Spring Boot, as well as fixes for edge-case bugs. https://github.com/komapper/komapper/releases/tag/v5.2.0
  • d

    dave08

    02/12/2025, 4:58 PM
    I have a case coming up more and more... a
    @KomapperPartial
    that has two parts... the WITH ... before the sql I need to put it in and the actual place I need it in (like adding a JOIN to that WITH, or an ORDER BY by it...). One possibility is having the annotation be able to receive an array of sql parts (using the same parameters in the class they're annotating), and then being able to use it:
    Copy code
    @KomapperPartial([
    """....""",
    """...."""
    ]) data class P(...)
    
    @KomapperCommand("""
       /*> p.1 */
    ....
       /*> p.2 */
    ...
    """) data class Q(p: P, ...)...
    this would help encapsulate a whole functionality in one partial.
    t
    • 2
    • 8
  • d

    dave08

    02/16/2025, 12:52 PM
    @Toshihiro Nakamura Can I refer to objects that I have in my KomapperCommand from a KomapperPartial? It's a bit funny to keep on having to pass them down in both...
    t
    • 2
    • 2
  • d

    dave08

    02/16/2025, 1:37 PM
    @Toshihiro Nakamura I think we once spoke about spacing before and after template placeholders... I'm wondering if somehow the adding of whitespace could be controlled in a future version of Komapper. Say
    /*% if ... */\n
    would add a new line, but
    /*% if ... *_/\n
    would suppress any whitespace after it and before the next text it contains (whereas
    /_*% if ... */\n
    would do the opposite) allowing to make the sql templates look nicer, while at the same time making printing out the generated sqls and testing against them simpler and nicer...
    t
    • 2
    • 1
  • d

    dave08

    02/16/2025, 1:39 PM
    _
    could be any character you decide... I just gave an example
  • d

    dave08

    02/17/2025, 1:17 PM
    Are there any plans to add
    /*%elif ... */
    or when blocks to templates any time soon? It's a bit cumbersome to have to use tons of if/ends...
    t
    • 2
    • 2
  • d

    dave08

    02/23/2025, 11:29 AM
    @Toshihiro Nakamura It seems like DryRunResult's sql when an error was thrown on a query with a flatMap returns the first query even though the error seems to be in the query inside the flatMap -- that makes sense since the dryRun can't have any idea of a runtime failure, but it makes it impossible to get a normal log with the sql and params being run when getting such a runtime failure... unless I'm missing something? (Regular runtime failures only give a small part of the sql that had bad grammar... which isn't too helpful in tracking down the problem)
    t
    • 2
    • 6
  • t

    Toshihiro Nakamura

    03/08/2025, 3:50 AM
    Hello everyone, We have released Komapper v5.2.1. In this release, we fixed an issue where retrieving data from PostgreSQL using R2DBC resulted in missing records and altered row order. https://github.com/komapper/komapper/releases/tag/v5.2.1