I am trying to create a person
record with the following code:
import Surreal from 'surrealdb.js';
...
const peopleFromSomewhere = await someProvider.getAllPeople();
// [{ email: 'some@email.com', fullName: 'Some Name' }, ... ]
for (const person of peopleFromSomewhere) {
const created = await db.create('person', {
email: person.email,
fullName: person.fullName
});
})
This creates a record with a randomly generated unique identifier, such as:
{
email: 'some@email.com',
fullName: 'Some Name',
id: 'person:b5pfovinz7zkxlz3s8er'
}
But if I run the same code again, the same data will be inserted, just with a different UID.
I would like to use the email
as a 'primary key' (using relational database terms) - to avoid inserting the same person
twice, with the exact same details (email address & full name). How can I do this?
const created = await db.create(`person:${person.email}`, {
email: person.email,
fullName: person.fullName
});
Only gives me:
{
email: 'some@email.com',
fullName: 'Some Name',
id: '⟨`person:some@email.com`⟩:w9m4l31bwti4472tdoax'
}
Which doesn't look quite right to me.
I expected:
{
email: 'some@email.com',
fullName: 'Some Name',
id: 'person:'some@email.com''
}
How can I create a person
record with the unique ID of an email address, so that I don't insert the same data twice?