With Dexie, can I get all objects in a table where an array field has a specific value as one of its elements?

情到浓时终转凉″ 提交于 2021-01-29 19:52:17

问题


I have a table where each object has a field that is an array of strings: for example, { people: ['John', 'Bob', 'Sue'] }. I need all objects in the table that have 'Sue' in the people array.

Can Dexie do this?


回答1:


Yes, using MultiEntry indexes you can do exactly that.

const db = new Dexie("testdb");
db.version(2).stores({
  groups: 'id, *people'
});

async function addRow() {
  await db.groups.add({id: 1, people: ['John', 'Bob', 'Sue']});
}

async function findSuesGroups() (
  return await db.groups.where('people').equals('Sue').toArray();
}

See other examples at https://dexie.org/docs/MultiEntry-Index



来源:https://stackoverflow.com/questions/60087180/with-dexie-can-i-get-all-objects-in-a-table-where-an-array-field-has-a-specific

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!