I have next config for indexed db
import Dexie from 'dexie';
const db = new Dexie("dbName");
db.version(1).stores(
{users: '++id, name,company,confirmPassword,email,password,*permissions'}
);
const saveClient = async (client) => {
return await db.users.add(client);
};
export {
saveClient
};
where permissions are array of objects
{
name: 'Alex',
company: 'Company',
password: 'Password',
confirmPassword: 'Password',
permissions : [{id:1}, {id:2}] //permisions
}
Should I describe this field special way to add new object to storage ?
You can store any structure in indexedDB including array of objects without describing it in an index. Indexes shall only list properties you want to use in your queries.
Indexes can be plain or multiEntry. Plain indexes works on the property itself while multiEntry indexes operate on each entry in arrays. However, those entries need to be plain values and not objects - since objects are not indexable in themselves.
So if your intent is to query all users that has a permission with id = X, you would need to store each permission as the plain ID number ([1, 2, ...]) and not as objects [{id: 1},{id: 2}, ...].