Having an issue with this D1 insert. The DB binding is fine (another function reads from the DB OK), but this insert just will not execute. It gets to the "Preparing to insert.." line OK and then black hole - not even an exception error. Simplifying by stubbing in values to avoid type mismatch issues didn't help either.
const insertSql =
INSERT INTO company_profile
(symbol, companyName, website, fullTimeEmployees, industry, overallRisk, description)
VALUES (?, ?, ?, ?, ?, ?, ?);
INSERT INTO company_profile
(symbol, companyName, website, fullTimeEmployees, industry, overallRisk, description)
VALUES (?, ?, ?, ?, ?, ?, ?);
;
for (const entry of data) {
console.log(Preparing to insert/update data for symbol: ${entry.symbol}Preparing to insert/update data for symbol: ${entry.symbol});
try {
const stmt = await DB.prepare(insertSql);
await stmt.bind(entry.symbol, entry.companyName, entry.website, entry.fullTimeEmployees, entry.industry, entry.overallRisk, entry.description);
const result = await stmt.run();
if (result) {
console.log(Data successfully inserted for symbol: ${entry.symbol}Data successfully inserted for symbol: ${entry.symbol}, result);
} else {
console.log(Insert failed for symbol: ${entry.symbol}Insert failed for symbol: ${entry.symbol}, result);
}
} catch (error) {
console.error(Failed to insert data for symbol: ${entry.symbol}Failed to insert data for symbol: ${entry.symbol}, error);
}
}