cornucopia icon indicating copy to clipboard operation
cornucopia copied to clipboard

Query docs

Open LouisGariepy opened this issue 3 years ago • 5 comments

Right now there's no way for users to add doc comments to their queries. We should make it possible to document queries from the SQL-side. For example:

--! universe
--? Select everything in the universe.
select * from Universe;

There are two outstanding questions with this:

  1. Syntax: is --? OK? How do we handle multiline docs? does the order of annotations matter (i.e. should --? go before or after --!, does it even matter)?
  2. What generated item should the docs apply to? The statement struct? the query struct? the query function?

Another related idea is to add auto-generated docs for some generated items like params structs. Something like /// This is the parameter struct for such_query

LouisGariepy avatar Oct 31 '22 19:10 LouisGariepy

How about:

-- File comment (ignored)

--! universe
-- Universe comment
-- Over multiple line
select * from Universe;

Virgiel avatar Nov 01 '22 00:11 Virgiel

Looks good to me!

LouisGariepy avatar Nov 01 '22 21:11 LouisGariepy

I think it could follow Rust docs patterns. And generate the docstrings in generated rust code too. https://doc.rust-lang.org/rust-by-example/meta/doc.html

Actually the focus here is the rust code, not the sql. (My opinion)

ricardodarocha avatar Nov 10 '22 23:11 ricardodarocha

What about adding a third dash? E.g --- This is a doc comment.

That way there would be a kind of symmetry with the triple slash for standard doc strings.

jacobsvante avatar Nov 11 '22 09:11 jacobsvante

@ricardodarocha That's the goal! Write documentation on SQL that will be converted to rust doc comments at codegen. This gives better IDE support and makes it possible to generate rust API docs for your queries.

@jacobsvante I like this idea!

LouisGariepy avatar Nov 13 '22 22:11 LouisGariepy