cornucopia-rs / cornucopia

Generate type-checked Rust from your PostgreSQL.
Other
759 stars 31 forks source link

allow multiline definition #150

Open xoac opened 1 year ago

xoac commented 1 year ago

Hi in case of long SELECT with many LEFT JOIN (when joins are optional) definition can be longer It would be nice if such code would be correct:

--: MyType (
--: name1?, name2?, name3?, name4?,
--: name5?, name6?
--: )
LouisGariepy commented 1 year ago

This would require a parser rework, but could be worthwhile. Its definitely doable in theory, since the old parser used to support this.

Another related question is if we should allow wildcard nullity declarations, like

--: MyType (*)

Where the star * meaning that all fields are declared null.

xoac commented 1 year ago

For my perspective this looks counter-intuitive. I mean without documentation I couldn't guess that * mean optional. Maybe *? would be better what would be similar to regex.

Truly I would prefer ability to join types and make whole types optional. In case of LEFT JOIN you want the whole structure optional not only fields.

--: MyType (a, b)
--: LeftJoinType(d?, e)
--: JoinedType (MyType, LeftJoinType?). 

But this is complicated to implement as LeftJoinType would require at least one NOT NULL field to be able distinguish null struct from struct with all optional fields.

ricardodarocha commented 1 year ago

Typescript syntax for optional field (NULLABLE) is ? question mark

I suggest question mark, because it is most intuitive way