I am in the process of integrating a javascript application with a third-party API that manages names in a database. The challenge I am facing is that the third-party application uses utf8_general_ci collation to determine name uniqueness, while my application needs to dynamically decide if a name already exists in their database to avoid duplicate errors. Here's how the process unfolds:
The user enters a name into my application: "somename"
My application sends a search request to the third-party API for "somename", which returns:
[
{
"id": 1,
"name": "Somënamë"
},
{
"id": 2,
"name": "somename somesecondname"
},
{
"id": 3,
"name": "somename someothername"
}
]
- My application must determine whether to create a new record for "somename" or use one of the existing results
In this scenario, my application needs to recognize that "somename" and "Somënamë" are considered equal under a utf8_general_ci comparison, and therefore should use the record with id=1, rather than attempting to create a duplicate entry.
In essence, I need to replicate the same string comparison behavior as the third-party database.
One approach I have explored involves directly using a mysql instance for comparison, like so:
SELECT IF(_utf8:string1 COLLATE utf8_general_ci = _utf8:string2 COLLATE utf8_general_ci, "true", "false") as equals;
However, this method proves to be too resource-intensive for situations where we may encounter thousands of results.
Is there a way to simulate this collation check in JavaScript somewhat accurately, without resorting to hosting a database on my end?