8000 Create tables at runtime? · dexie Dexie.js · Discussion #2166 · GitHub
[go: up one dir, main page]

Skip to content
Discussion options

You must be logged in to vote

Updating the schema runtime is possible but I would not recommend it, and like with SQL, there are techniques to optimize query performance anyway by choosing smart primary keys or indexes.

My recommendation would be to use a compound index where the first part represents the channel ID and the second part the message ID. That way you could do all kinds of queries the same optimized way as if each channel had its own table.

Example:

const db = new Dexie('messaging') as Dexie & { messages: Message };
db.version(1).stores({
  messages: `
    ++messageId,
    [channelId+messageId],
    [channelId+timeStamp]`
});

To query the 10 recent messages from a certain channel:

await db.messages
  .where(

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by dfahlander
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
0