I have a function that adds an entry to my indexedDB database:
const dbParams = {
// Update this when changing the db schema
dbVersion: 1,
// Database, object store names
databaseName: "CropViewConfigData",
datesConfigStoreName: "datesConfig"
};
// Create db instance
const db = new dexie(dbParams.databaseName);
// Define db schema
db.version(dbParams.dbVersion).stores({
// First param is primaryKey followed by indexes
[dbParams.datesConfigStoreName]: ",name, *fields"
});
// Open the database
db.open().catch(function(e) {
console.error("Failed opening indexedDb");
});
// Store a new configuration into the database
export async function storeDateConfig(name, fields) {
// Throw error if name is not defined
if (!name || name === "") {
throw new nameException("Config name is not valid");
}
// Throw error if no fields
if (!fields || fields.length < 0) {
throw new fieldsException("Fields data is not valid");
}
// Throw error if name already exists
const savedConfig = await db.datesConfig.get(name);
if (savedConfig) {
throw new nameException("Name already exists");
}
// Add data to db
await db.datesConfig.add({ fields: fields }, [name]);
}
Now according to the docs, ",name, *fields"
should mean that Primary key is neither inbound nor auto-incremented, 'fields' contains an array of keys (*)
So I should be able to pass the key to the .add
function?
But I am getting this error:
message:"Failed to execute 'add' on 'IDBObjectStore': The object store uses in-line keys and the key parameter was provided." name:"DataError"
What am I doing wrong?