在我的 React Native Android 应用程序中,我在 WatermelonDB 上创建了一个表。当我使用批处理从组件向表中插入新记录时,我收到TypeError: Cannot read property 'id' of undefined
批处理中抛出的错误。
这是使用Promise
对象列表调用批处理的地方:
await database.action(async () => {
const allRecords = this.prepareInsertion(smsTransaction, records);
await database.batch(...allRecords);
console.log(allRecords.length);
});
prepareInsertion(smsTransaction, messages) {
return messages.map(async message => {
try {
return smsTransaction.prepareCreate(transaction => {
const parsedFields = parseFields(message);
transaction.type = parsedFields.type;
transaction.read_at = parsedFields.read_at;
});
} catch (e) {
console.log(e);
}
});
}