schemats icon indicating copy to clipboard operation
schemats copied to clipboard

Why nullable columns are optional?

Open wirekang opened this issue 1 year ago • 3 comments

CREATE TABLE T1(
  c1 varchar null
)

become

interface T1 {
  c1?: string | null
}

c1 can be string or null, but could it be undefined? It would be great if there is an option to disable optional marks on nullable columns.

wirekang avatar Oct 18 '22 06:10 wirekang

yeah adding an option for that makes alot of sense!

the reason it's optional is mostly due to the fact i use those schemas via a typescript to json schema validator, and i don't expect to have to pass in nulls for things. But it definitely isn't the 'truth' and so this issue makes more sense.

Would you like to try raising a PR for this?

We would need to pass in another cli option (--no-undefined) and use that in this line here:

https://github.com/vramework/schemats/blob/389d0a2f2f4f45790f8568e4d90834decf9770de/src/generator.ts#L40

yasserf avatar Oct 18 '22 08:10 yasserf

Thank you for responding quickly! I don't have time right now, but I'll submit PR for issues I recently wrote in a month if possible.

wirekang avatar Oct 18 '22 08:10 wirekang

sounds good! if I find myself touching the library i'll bundle in these changes as well!

yasserf avatar Oct 18 '22 08:10 yasserf