Dexie.js icon indicating copy to clipboard operation
Dexie.js copied to clipboard

How to use dexie 4.0 ?

Open xkmy opened this issue 2 years ago • 3 comments

Version : 4.0.1-alpha.10

Have these functions of 4.0 mentioned in the official document not been released yet? I have installed the 4.0.1-alpha.10 package, but these functions cannot be used, the following is a screenshot of dexie official website: image

Below is my code:

image

Help me to see, thank you!

xkmy avatar Apr 13 '23 09:04 xkmy

These features are only not possible to use yet. It's just in the road map docs as an example of what will become possible.

dfahlander avatar Apr 13 '23 11:04 dfahlander

I have an order table with a large amount of data (more than 10,000). When I query, paginate, and sort him according to conditions, I encounter a problem. The sorted results will only take effect on the current page. This Not what I expected, here is the pseudocode:

const list = await db.orders.where({}).offset(page).limit(pageSize).sortBy('payTime')

My current solution is to manually paginate after the sort is done, like this:

let list = await db.orders.where({}).sortBy('payTime')
list = list.slice((page - 1) * pageSize, page * pageSize)

This can achieve the correct effect, but when the amount of data is large, the query will become stuck. In the case that 4.0 has not been released, is there a better way?

Looking forward to your reply, thank you!

xkmy avatar Apr 14 '23 02:04 xkmy

Until 4.0 prod is here, what you need to implement is a smart paging within your app that can utilize indexes for sorting and, if using paging, keeping last key from previous page in state so you don't need to use offset.

https://dexie.org/docs/Collection/Collection.offset()#a-better-paging-approach

If the query is less complex though, you might also have a look at how this app implements it using a simpler approach for sorting/paging:

https://codesandbox.io/s/svelte-with-dexie-livequery-2n8bd

dfahlander avatar Apr 14 '23 05:04 dfahlander