kiranandcode / petrol

Petrol's an OCaml SQL API made to go FAST.
https://kiranandcode.github.io/petrol/petrol/index.html
Other
113 stars 6 forks source link

Complete example? #4

Open garyrob opened 1 year ago

garyrob commented 1 year ago

It would be very helpful to relative newbies to OCaml, such as myself if you had a single complete example of using Petrol. For instance, you have:

(* ... somewhere at the entry point *)
let () =
   let open Lwt_result.Syntax in
   (* ... *)
   let* conn = Caqti_lwt.connect url in
   let* () =
      Petrol.VersionedSchema.initialise
        DB.db conn in
   (* ... *)

I'm not sure what go in the line that is commented after let open Lwt_result.Syntax in or what would go after

Petrol.VersionedSchema.initialise
        DB.db conn in

in order to get a basic working example. To explain more concretely what problem I'm having in my newbie state: if I wanted to use your insert_text function after the line mentioned above, I don't know what argument I would pass to it to represent the db parameter. Would it be conn? DB.db? It would just be nice if it was made completely clear how to create a db variable that could be passed to a function like insert_text.

I realize that if I wasn't a newbie to OCaml I would probably have no issues. But I'd like to use Petrol in the course of my early learning; I'd like to be able to use a sqlite database as a starting point, and play to learn. Also, something very high-level like Petrol (compared to Caqti) seems like it would be especially advantageous to newbies. So it seems like giving newbies something that worked would make a great starting point.

Of course, you may find this training use-case to be outside the scope of what you want to do. That would be completely understandable, and I certainly wouldn't blame you in any way for simply closing this issue with no action. But, on the other hand, it doesn't seem like it would be very difficult to provide an example source file that would be a complete working example that could be run after doing opam install petrol, and it would be helpful to OCaml newbies. So, I didn't think it was completely out of line to mention it as a possibility.

Please take all this as just a friendly suggestion, with no expectations.

I did try cloning the github project and doing dune runtest, but I got all kinds of errors. This is on macos, and you mention issues with run-time loadable extensions that I'm hoping only apply when working with your project source rather than using the packaged library via opam and dune. Although I don't know that.

Thanks for listening to this particular newbie!

kiranandcode commented 1 year ago

Hi @garyrob , yes, that seems like a good idea. It might be good to have a minimal example available so that people can get started with the library.

I'll try and add an example soon.

In the meanwhile, you can find snippets of a working example in the test/ directory. In particular: