I’m looking for suggestions to improve my current workflow. My process is as follows:
I receive an input item with a body.
I perform a PostgreSQL SELECT query to retrieve a list of terms that will be used for filtering.
I use an “if” condition to filter out any message that contains any of the specified words.
Finally, I output the valid messages.
My question is: if step 2 returns multiple items, should I merge or combine all the term bodies into a single filter before applying step 3? or is there other way to do it. as of now I merge combine all the items then do my if but that seem really clunky.
so is there a way to check “if contain in the list” vs “if contains in string” ?
I think what you have works fine, because there should be a balance between complexity to do the right thing vs ease of maintenance. I mean that if you have set something up in a way that works and is allowing you to comfortably maintain it, that should be fine. But if you absolutely want to make some changes, maybe the code block could help you.
The code block can allow you to filter in one go. Here’s an example where the input array in the JavaScript code block is the input item you mention that you receive with your body.
The HTTP request is just a simulation of your SELECT query. I don’t know what sort of data is being returned by your query, but I’d like to assume it’s an array (which is what I tried to demonstrate in my example).
Thanks for your input. Yes my stuff works but I’m wondering if there is a better way to do this type of filtering. Let me play with your code to see if that could be the answer.
Maybe there is a better way to do this. When you perform the PostgreSQL SELECT, you could add a field (implement the logic of if contain in the list ) in your sql. Then you could use it directly.
I ended up preferring your approach. no code to maintain and directly link with the DB by executing a custom select query with the postgre node. thanks