roddyyaga / ppx_rapper

Syntax extension for writing SQL in OCaml
Other
139 stars 18 forks source link

Add support for `let%rapper` pattern captures. #13

Closed rizo closed 2 years ago

rizo commented 3 years ago

Hi! First of all, thanks for a great ppx! :)

This is just a proposal to allow for an alternative way to write the ppx using let declarations. This is functionally identical to the current version but, in my opinion, looks a little bit less noisy and reduces code nesting.

Here's how the example from the README would looks like:

let%rapper my_query =
  get_opt {sql|
    SELECT @int{id}, @string{username}, @bool{following}, @string?{bio}
    FROM users
    WHERE username <> %string{wrong_user} AND id > %int{min_id}
  |sql}
Before ```ocaml let my_query = [%rapper get_opt {sql| SELECT @int{id}, @string{username}, @bool{following}, @string?{bio} FROM users WHERE username <> %string{wrong_user} AND id > %int{min_id} |sql}] ```

I can update the README if you are happy with this change.

roddyyaga commented 2 years ago

Sorry for taking so long to get to this! Looks good, I'm happy for you to add an example of this to the README if you want but I'd prefer to keep most of the examples in the old syntax (personally I think the new one looks better most of the time but is a bit confusing if there are flags like record_out).