Help with designing schema of a document represented in tinybase #65
vineetdigit
started this conversation in
General
Replies: 1 comment
-
I would try to keep everything in tables - since these feels like a relational model, and you can maybe use the relationships module to connect the documents to the pages. So maybe something like this? const store = createStore();
store.setTables({
documents: {
docA: {title: 'The title for doc A'},
docB: {title: 'The title for doc B'},
// ...
},
pages: {
pageA1: {doc: 'docA', order: 1, content: 'blah blah'},
pageA2: {doc: 'docA', order: 2, content: 'blah blah'},
pageB1: {doc: 'docB', order: 1, content: 'blah blah'},
pageB2: {doc: 'docB', order: 2, content: 'blah blah'},
// ...
},
}); The relationships module could then be used something like: const relationships = createRelationships(store);
relationships.setRelationshipDefinition(
'pagesToDocuments', // relationshipId
'pages', // localTableId to link from
'documents', // remoteTableId to link to
'doc', // cellId containing remote key
);
console.log(relationships.getRemoteRowId('pagesToDocuments', 'pageA2'));
// -> 'docA'
console.log(relationships.getLocalRowIds('pagesToDocuments', 'docB'));
// -> ['pageB1', 'pageB2'] |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm little confused how to design schema for a document with tinybase. For the sake of simplicity, let's assume that the document is as follows
From what I understand, tinybase allows either key=value pairs or tables. So in order to represent the document, do I need to store title as a key=value pair and pages as a table? If yes, then how do I create one-to-many relationship from the document to the pages?
Any help?
thx
Beta Was this translation helpful? Give feedback.
All reactions