I am attempting to insert data into a Postgresql database from an Express.js server using Sequelize.
Before inserting the data into the DB, I need to program to look and see if the data is already inside the table. The data can belong to one person for one day and sometimes there is already data associated with the specific person for the specific day. It is a find or create function that is utilized like so,
record.findOrCreate({
where: {
date: data.date,
name: data.name,
},
defaults: data,
})
I need to see if the person's name matches the data being inserted, but I would like to test the value of the name currently in the database as being a substring on the data name being inserted. Is there a way to do this with sequelize? The logic being something similar to what is below.
WeeklyChargeRecord.findOrCreate({
where: {
weekend: data.weekend,
name: data.name.includes(name)
},
defaults: data,
})
The reason I am attempting this method is that sometimes the names for each person may include their full name (first, last, & middle names) for that data that is being inserted into the data base. But the data already in the data base is just their first and last names.