My function is simple. Create table, bulk put data and retriew object based on index.
const db = new Dexie('data');
const dataToInsert = [{id: "aaaa", name: "bbb"}]
function data() {
var exists = await Dexie.exists("data");
if (!exists) {
await db.version(1).stores({
data: 'id,name'
});
await db.geo.bulkPut(dataToInsert);
}
var record = await db.geo.get("aaaa");
}
I can see everything is inserted. But GET function is returning:
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'get')
Even db.geo is undefined... any idea why?
The problem is you haven't define geo table schema so Dexie don't know about it.
If you meant data schema instead of geo schema then to fix just change data to geo in schema definition
const db = new Dexie('data');
const dataToInsert = [{id: "aaaa", name: "bbb"}]
function data() {
var exists = await Dexie.exists("data");
if (!exists) {
await db.version(1).stores({
data: 'id,name'
});
await db.data.bulkPut(dataToInsert);
}
var record = await db.data.get("aaaa");
}
Or add missing geo schema.