Delete political messages from Messages app, using SQL queries

In the Messages app, I want to delete and report junk on all messages that contain any text from a list of specific texts, in my case political ones, asking for contributions.

I have found useful scripts calling sqlite3 in an SQL query on Apple’s chat.db file, and then calling regex to find the text of message text, as discussed in Accessing Messages App Sqlite database.

Now, I would like to:

  1. Identify the text in Messages’ data, using those chat.db file SQL queries

  2. Create a list of those text messages in Messages’s database of active messages

  3. Loop through the list of those messages

  4. Delete each message in that loop that contain specific texts from that list.

I am at a lost on how to accomplish this task, and would welcome any insight.

Is the script published here of any use ?

https://stackoverflow.com/questions/48086287/reading-imessages-with-applescript

S

The SQL database is only a local copy (cache) ! Any changes made to it will destroy the iCloud sync and will not really delete the messages!
Therefore, the database should only be read!