Open garyrob opened 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:
conn
to a Sqlite3 database, you can call the functions defined in Person.Sql
let age = int_of_string age in
let* _ = Petrol.StaticSchema.initialise db conn in
let* _ = Person.Sql.insert Person.{name;age} conn in
Lwt.return_ok ()
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:
I'm not sure what go in the line that is commented after let open
Lwt_result.Syntax in
or what would go afterin 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 thedb
parameter. Would it beconn
?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 likeinsert_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!