Replies: 1 comment 1 reply
-
That's a smart idea and really cool. I think there should be a better way to satisfy the type system than |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Inspired by the (pretty great) new helpers for writing migrations, I wrote an extension for ColumnDef that has the potential to also shorten writing common database checks.
The code is pretty simple, but I had to go a bit of a detour to get the column name as Iden from the ColumnDef using Alias.
This results in the following change:
Before:
After:
I'd say second snippet is easier to read and write by reducing the repetition of the column name.
The obvious downside is that it is only possible to apply checks that span one column, but I'd say that's still a pretty common use-case.
I plan to write a similar helper function for String enum value checks (on sqlite), but I'm not sure if there is any other common methods that are useful to abstract for a single column.
Beta Was this translation helpful? Give feedback.
All reactions