yawaramin / re-web

Experimental web framework for ReasonML & OCaml
https://yawaramin.github.io/re-web/re-web/index.html
MIT License
261 stars 8 forks source link

Investigating handling databases #35

Closed hamza0867 closed 4 years ago

hamza0867 commented 4 years ago

Hello @yawaramin

Thank you for the great work on this framework. I want to suggest adding the handling databases part to this framework, this way people can use re-web to write their json apis with databases management included. What I think is missing is something like an orm that would make handling requests to the database easy. The approach I am thinking of is to write a ppx that generates code that follows the example found here.

We will have a module that represents our Entity and the usage of the ppx can be something like:

module Entity = [%reweb.entity 
 type t = {
    id: int,
    title: string,
    completed: bool,
  }
]

and then the ppx will generate the whole module Entity found in the example.

And for the Repository module I still don't have a clear idea on how to do it because the repository needs to get the connection pool from somwhere. So maybe some combination of a functor with a ppx, the functor to inject the connection pool and the ppx to generate the remaining code ?

I would like to hear your thoughts on this.