sqlgg
sqlgg copied to clipboard
Add debugging-metadata and tracing directly to OCaml traits-module
This PR implements an alternative to #117, making tracing-information non-optional (and thus requiring no build-system changes), instead requiring traits-implementations to be updated to accept the new tracing-information.
This is a breaking change for custom traits-implementations.
The built-in traits implementation use ocaml-trace, if present in the installed world (opam install trace), to generate tracing-spans for each SQL statement.
All of the additions are noops at runtime if the user does not have ocaml-trace installed, and doesn't use a custom traits implementation.
The diff in the generated output is as following:
@@ -7,6 +7,10 @@ module Make (T : Sqlgg_traits.M_io) = struct
module IO = T.IO
let get_something db ~user_id callback =
+ let __sqlgg_sql = ("SELECT DISTINCT(some_name)\n\
+FROM some_users\n\
+WHERE user_id = ?")
+ in
let invoke_callback stmt =
callback
~some_name:(T.get_column_Text stmt 0)
@@ -16,12 +20,14 @@ module Make (T : Sqlgg_traits.M_io) = struct
T.set_param_Int p user_id;
T.finish_params p
in
- T.select db ("SELECT DISTINCT(some_name)\n\
-FROM some_users\n\
-WHERE user_id = ?") set_params invoke_callback
+ T.select ~operation:"SELECT" ~span_name:"get_something" db __sqlgg_sql set_params invoke_callback
module Fold = struct
let get_something db ~user_id callback acc =