How to make many to many relation in browser sync storage?

41 Views Asked by At

I'm creating an extension which is gonna allow users to tag comments. In an SQL database I would create tables like that:

comments:
  id int
  text string

tags:
  id int
  tag_name string

comment_tags:
  comment_id int
  tag_id int

But WebExtensions API provides us pretty few methods(https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/storage/sync#Methods) with "key value" access

I have some ideas like to store this as a bunch of keys, like so:

{
  "comment_1": { comment data },
  "comment_2": { comment data },
  "tag_1": { tag data },
  "tag_2": { tag data },
}

where 1 and 2 are ids and to store relations either in comment's and tag's data or as another key "comment_tags_1_2". But both ways are inconvinient.

What is a typical way of solving this task?

0

There are 0 best solutions below