Open tobiasBora opened 7 years ago
It would be very nice indeed.
Note that OCaml is typed, which poses challenges. Django et al. work in an untyped setting and exploit runtime information about the structure of the data, which we can not do. Expressing complex database queries in OCaml and persuading the OCaml type checker about the type of the output (as your first bullet suggests) is notoriously difficult. It can be solved by adding preprocessing into the mix (like PGOcaml and Macaque do), but then we are effectively talking about non-OCaml syntax.
Still, there is lot we can do within the OCaml type system. For example, displaying a table and modifying one entry at a time (somewhat covering bullet 4) based on a GADT description of its schema is entirely feasible.
Contributions towards this would be more than welcome :).
Honestly, this has pretty much nothing to do with ocsigen-start, except that we would like to use it. :)
Non exhaustive previous work on the question:
Type embeddings:
Syntax-based:
And that's only in OCaml, There is also a significant Haskell and Rust literature (notably, http://diesel.rs/). A good amount of if is equally unsatisfying.
We just don't have a good solution for that in OCaml at the moment and the tasks is hard enough that nobody figured it out properly in the last few years. I don't think inventing something ad-hoc just for eliom is a good idea.
Honestly, this has pretty much nothing to do with ocsigen-start, except that we would like to use it. :)
@Drup, there is a user interface aspect that does have to do with Ocsigen Start (imagine a potential admin panel for managing tables). But I agree with you with respect to the core of the problem :).
Hello,
It would be great to have better ways to deal with databases. Here are a few things that would be very nice to have:
Everything listed above is already present in Django (python web framework). You can look at how models are used in django, but basically it's very simple: just create a class whose attributes describes the SQL database. This provides all the getters/setters to create, modify, filter, and add an object in the database. And just connect to the
/admin/
part of the website, and you will be able to edit all the objects from you browser.Here is an example:
then update the database using:
and in the python code, deal with objects with something like
You can do much more things (like describing how the objects would appear in the admin panel, you can specify a lists of values for the type fields...). You can read more example here: https://docs.djangoproject.com/fr/1.10/topics/db/queries/. Having such tools in ocaml would make it much easier to use.
Thank you.