Non hardcoded strings in sql()
This:
produces:
I would really prefer to have one source of truth for this enum. This way I have one place from where I can drive the type and all the other stuff.
4 Replies
Your code looks okay. What is the issue here ?
Well i'd like the CHECK to actually check for the values not for
?
. I'd like the resulting CHECK to be CONSTRAINT "is_valid" CHECK("some_table"."kind" IN ('win', 'sbst', 'tbst', 'chop'))
- without having to hardcode those string values which is what I am forced to do now. It makes maintaining and keeping things in sync more ddifficult and error prone instead of having one single source of truth.Ah I see the problem
This is also a new discovery for me too. I realized you would need to use
sql.raw
to actually transfer your JS strings directly into the SQL statement
If not, the JavaScript injection seems to be treated as parameterized statements/placeholder-things, which are not appropriate in a CHECK statement
So your solution is
oh, thanks a lot man!