• atombender 4 hours ago
    I'm a big fan of sqlc (which this is essentially a port of), so this is great to see.

    I think the sqlc approach is ultimately the right one for integrating SQL into code because it allows queries to be expressed using the full syntax of native SQL, and only needs to handle the input/output glue. So you get the best of both worlds: Pure SQL unencumbered by non-SQL code, and type safety. ORMs will always struggle to catch up with SQL's richness and expressiveness.

    I've not used Gleam for anything yet, but this makes me more excited to try it out.

    [-]
    • ncruces 29 minutes ago
      The problem with sqlc is dynamic queries (mostly dynamic filters and ordering, which don't really affect type safety of the parameter or result-set mappings).

      Even after years, the solutions are unsatisfactory from a database query planner perspective.

      [-]
      • atombender 15 minutes ago
        A minority of my sqlc queries use CASE expressions, but I've never had an issue with them. As far as I can see, Postgres is good at optimizing them away. Is that not generally the case?

        I wonder if a sufficiently smart sqlc could do the optimization itself. Basically have an SQL parser that is able to identify dynamic parts statically and encoding an efficient representation that allows constant folding at runtime.

        Another weak point in sqlc is the absence of any composability, so every query has to be self-contained. But views can help you with that.

        [-]
        • ncruces 12 minutes ago
          PostgreSQL is probably smarter than SQLite. :)

          Anyway, at minimum you have prepared statements where a given plan may be great for one execution and terrible for the next. Maybe the database re-prepares for you, and then it's the same as a dynamic query.

  • johtso 2 hours ago
    sqlc always seemed like a really neat concept to me. I love the idea of being able to write my queries as raw SQL in separate files, would make everything so much more interoperable with other tools. Having your queries defined as strings inside some other programming language always struck me as not so awesome.

    I'd love to see something like this for Typescript and Effect's SQL integration with schemas.

    [-]
  • jiehong 55 minutes ago
    Nice!

    It reminds me of Jooq in Java-land. Does Parrot also try to fill-in the gaps in support between databases so that the same query works on all databases?

    [-]
    • daniellionel 49 minutes ago
      hi, author here! it does not no :) it takes the json description of the sql queries generated by sqlc and converts them to gleam code. but if sqlc supported that feature, parrot could also take advantage of it.
  • killingtime74 8 hours ago
    What is Gleam? No obvious hits when googling.
    [-]
    • conroy 8 hours ago
      https://gleam.run/ - Gleam is a friendly language for building type-safe systems that scale!
      [-]
      • fzeindl 7 hours ago
        What is the benefit over Elixir?
        [-]
        • victorbjorklund 4 hours ago
          As an elixir dev I'm jealous that gleam can transpile to JS as a target. Must make so interesting things possible.
          [-]
        • isodev 6 hours ago
          Static type checking and Gleam can compile to JavaScript. Gleam and Elixir can be mixed in the same project too, so it’s easy to start adding Gleam to an elixir code base or use Elixir libraries in Gleam.
        • jesperwe 7 hours ago
          Strong typing built in from the start. More approachable syntax (unless you are used to Ruby).
          [-]
          • filmor 5 hours ago
            Static typing. Elixir already has strong typing (no implicit conversions).
  • jsight 7 hours ago
    So, basically sqlc for Gleam? Sounds nice.

    I wonder how Gleam compares to the type checking support being added to Elixir?

    [-]
    • m8s 5 hours ago
      The two feel very different. Elixir is introducing gradual set-theoretic typing (https://hexdocs.pm/elixir/1.18.4/gradual-set-theoretic-types...) while Gleam has a static Hindley-Milner style type system.

      To me, Gleam feels like if Elm’s type system met Rust’s syntax. I really like it. But I also really liked Elixir too, I just can’t live without Gleam’s type system anymore.

      [-]
  • seivan 3 hours ago
    The best query builder I’ve seen is Kysely and it works because of anonymous sum types. So far no other library in any other language has come remotely close. You’d think Rust would have that level of type safety, but alas no.