With the release of r261 (started rollout last night) we add support for running connector functions as an automations action. This addition reminded me of one of the greatest connectors hacks of all time. I was wondering if I could use this to around the lack of expression editor in automations.
The initial case I ran into where I wanted expressions was to generate random strings for table records -
Most (maybe all) Tulip instances have a “Connectors Demo” SQL connector that can be used, this already has authentication details, making it a good sandbox to run SQL queries.
- Create a connector function
- Add the query
select md5(NOW()::text) as random_stringto this function
- Add a random_string output
md5 hashes the current time into a string, this time includes seconds down to 10.000ths , meaning unique values is nearly guaranteed.
select CAST(FLOOR(RANDOM()*100000000000000) as text) as random_string; is another query that will guarantee a unique string]
From your automation:
4. Add an action to your automation, calling this function, and store its output to a variable
5. Use this variable wherever you need it! including as the id field on the table record creation action
Obviously, multiple random strings can be created as needed, for separate tables.
There are a bunch of other ways I could thinking about using this functionality:
Multiplication, which could then be used downstream in your automation:
…and probably much much more.
Hope this unblocks someone!