Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use with ocaml-mariadb #62

Open
Kingdutch opened this issue Aug 20, 2020 · 0 comments
Open

Use with ocaml-mariadb #62

Kingdutch opened this issue Aug 20, 2020 · 0 comments

Comments

@Kingdutch
Copy link

I use Mariadb as backend so I thought I'd use ocaml-mariadb instead of ocaml-mysql as transport. The following code almost works (in the sense that it nearly builds, haven't actually run it yet) but I have a few questions.

include Ppx_mysql_runtime.Make_context({
  module IO = Lwt;

  module Prepared = {
    type dbh = Mariadb_with_lwt.t;

    type stmt = Mariadb_with_lwt.Stmt.t;

    type stmt_result = Mariadb_with_lwt.Res.t;

    type error = Mariadb_with_lwt.error;

    let wrap = (f, x) =>
      Lwt.Infix.(
        Lwt.catch(
          () => Lwt_preemptive.detach(f, x) >>= (v => Lwt.return_ok(v)),
          exn => Lwt.return_error(exn),
        )
      );

    let create = Mariadb_with_lwt.prepare;

    let close = Mariadb_with_lwt.Stmt.close;

    let execute_null = (stmt, args) =>
      wrap(Mariadb_with_lwt.Stmt.execute(stmt), args);

    let fetch = Mariadb_with_lwt.Res.fetch;
  };
});
  1. The execute_null function takes a string option array, however from what I can tell ocaml-mariadb takes Field.t instances. I could write a small wrapper here but I'm not sure how to get type information out of the string option array passed to execute_null to map it to what ocaml-mariadb expects.

  2. I'm unsure what the wrap function needs. The Mariadb_with_lwt is the lwt nonblocking implementation of ocaml-mariadb taken straight from their examples (mariadb_with_lwt.re). It appears that the type signatures are already result based so they don't need the exn -> result wrapping that is used for ocaml-mysql.

  3. Possibly should be a separate issue but how would I use connection pooling? Would it beat all needed? I don't think either ocaml-mariadb or ocaml-mysql seems to support it? Does ppx_mysql have anything special for it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant