dexie everyuniquekey和srause

发布于 2025-01-25 11:51:13 字数 765 浏览 4 评论 0原文

我正在为Quasar/Electron开发一个应用程序,并将Dexie/IndexedDB用于我的数据库。我想在数据库中找到包含我的事件ID和狗ID的所有不同记录(两个密钥索引字段)。我能够使用以下代码来执行此操作:

await myDB.runTable
   .orderBy('[fk_event+fk_dog]')
   .eachUniqueKey((theDuo) => {
   this.runsArray.push({eventID: theDuo[0], dogID: theDuo[1]})
  })

我正在使用一个合并良好的组合密钥。但是,我需要拥有更多的记录,而不仅仅是钥匙。我还需要几个字段,这可能吗?

我试图在使用Where功能的同时,在使用唯一的密钥功能的情况下获得记录,但这似乎不起作用。

我需要在特定事件的桌子上找到所有独特的(独特的?)狗。并获取他们的相应信息。我不确定是否有更好,更有效的方法来做到这一点?我随时可以拉出所有记录并循环循环以构建一个自定义数组,我只是希望在桌子上阅读级别进行此操作。 (是的,即使这些是收藏品等,我仍在桌子/记录中:p)。

即使以上代码也为我提供了所有事件,我也可以用过滤器拔出所需的内容。我只是在想在阅读级别上做到这一点会更快,更有效。

this.enteredRuns = this.runsArray.filter((theEvent) => {
    return ( (theEvent.eventID == this.currentEventID) )
  })

I'm developing an application in Quasar/Electron and using Dexie/IndexedDB for my database. I want to find all distinct records in the database that contain both my Event ID and a Dog ID (both key indexed fields). I am able to do this with the following code:

await myDB.runTable
   .orderBy('[fk_event+fk_dog]')
   .eachUniqueKey((theDuo) => {
   this.runsArray.push({eventID: theDuo[0], dogID: theDuo[1]})
  })

I'm using a combined key which is working well. However, I need to have more of the records than just the keys. I need a few more fields, is this possible?

I was trying to get records with the unique key function while also using the where function, but that doesn't seem to work.

I need to get all the unique (distinct?) dogs in the table that are in a particular event. And also get their corresponding information. I'm not sure if there is a better, more efficient way to do this? I can always pull out all the records and loop through them to build a custom array, I was just hoping to do this at the table read level. (yeah I'm still in tables/records even though these are collections etc. :p ).

Even the above code gives me all the events, and I can pull out what I need with a filter. I just was thinking it would be faster and more efficient to do it at the read level.

this.enteredRuns = this.runsArray.filter((theEvent) => {
    return ( (theEvent.eventID == this.currentEventID) )
  })

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

请别遗忘我 2025-02-01 11:51:13

尝试

await myDB.runTable
  .orderBy('[fk_event+fk_dog]')
  .clone({unique: "unique"})
  .toArray()

我知道这没有记录在记录的过程中,但是应该在提取整个对象的同时使用唯一的光标,而不仅仅是键。您不能与在哪里结合使用,但是可以使用.filter。请注意,并非所有具有扫描记录的记录都会以相同的键跳过记录 - 仅选择第一个访问的记录。

Try

await myDB.runTable
  .orderBy('[fk_event+fk_dog]')
  .clone({unique: "unique"})
  .toArray()

I know this isn't documented but it should do the work to use unique cursor while still extracting the whole objects and not just the keys. You cannot combine with where but you could use .filter. Just be aware that not all records with be scanned as it will jump over records with same keys - selecting the first visited records only.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文