roddyyaga / ppx_rapper

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

Proposed breaking change to API - generated queries to have DB connection as last parameter rather than first #4

Closed roddyyaga closed 4 years ago

roddyyaga commented 4 years ago

Heads up for any ppx_rapper users: I'm planning on reordering the signature of generated queries by moving the connection parameter.

let update =
  [%rapper
    execute
      {sql|
      UPDATE things
      SET value = %string{value}
      WHERE id = %int{id}
      |sql}
      record_in]

will go from having type

(module Caqti_lwt.CONNECTION) ->
{id: int; value: string} -> (unit, [> Caqti_error.call_or_retrieve ]) result Lwt.t

to

{id: int; value: string} -> (module Caqti_lwt.CONNECTION) -> (unit, [> Caqti_error.call_or_retrieve ]) result Lwt.t

This is to make using queries with connection pools nicer. With a function execute defined as

let execute query = Caqti_lwt.Pool.use query pool

you will be able to do

let calls_update { id; value } =
  execute @@ update { id; key; value; account_id }

rather than

let calls_update { id; value } =
  execute @@ fun conn -> update conn { id; key; value; account_id }

Please let me know if this would cause any problems for you (other than having to update affected code).

hamza0867 commented 4 years ago

I like this change

roddyyaga commented 4 years ago

@hamza0867 It's in version 2.0!