How to enforce constraints in Snowflake table from Retool app?

Given a situation where we need to enforce table constraints when user performs CRUD Snowflake SQL operations from Retool:

So I was thinking maybe we could create constraint check query from Retool.
Something like count all rows that violates table constraint:

SELECT COUNT(*)
FROM TABLE_A
WHERE (A={{ param1 }} AND B={{ param2 }});

What is recommended approach to construct query Dependency in Retool so that query will only run if the check passes?

Hello @skim-rgare,

Interesting question. I would say that you could use a JS Query to check the values that a user has inputted into a new row meet the constraints you are looking to enforce.

Are you having users in your use case enter in multiple rows into a table at once?

Another option is to use the Form Component to hold input values, then on submit button click, run a validation JS Query against the user inputted data first and then if the criteria is all met, go ahead and submit the data to the table.

The logic would involve chaining in an 'on success' event of submitting if the JS Query returns a true boolean and a 'false' if any one of the conditions are not met.

With an 'on failure' you could trigger a modal popup that could then be fed additional data from the JS Query to give the user greater context on which values do not meet the constraints.

1 Like