Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add options to Client.Attach and Client.Detach APIs #822

Open
hackerwins opened this issue Mar 12, 2024 · 0 comments
Open

Add options to Client.Attach and Client.Detach APIs #822

hackerwins opened this issue Mar 12, 2024 · 0 comments
Labels
enhancement 🌟 New feature or request

Comments

@hackerwins
Copy link
Member

hackerwins commented Mar 12, 2024

What would you like to be added:

In some cases, users may prefer to store the original document content in a service DB rather than in Yorkie. This results in the document not adhering to the Single Source of Truth (SSOT) principle and causes duplication of the document between Yorkie and the service DB. Therefore, a separate policy is necessary to maintain consistency.

To address this scenario, it is proposed to add options to Client.Attach and Client.Detach and provide the following guideline:

The main idea is to consider Yorkie Document as the primary source of truth during editing and switch to the service DB as the primary source after editing is completed.

A. Start Document Editing:

  • When editing begins, first fetch the key and content of the document stored in the service DB.
  • Attach Yorkie Document using this key, with the createIfNotExists: true option, along with the content stored in the service DB.
  • If the document has already been created in Yorkie by another client, receive the content being edited, and if not created, create the Yorkie document using the content stored in the DB.
Screenshot 2024-03-12 at 4 29 54 PM
const doc = new yorkie.Document(`key`);
client.attach(doc, {
  createIfNotExists: true,
  initialContents: contents
});

B. Finish Document Editing:

  • Upon completion of editing, store the document content in Yorkie in the service DB.
  • When detaching, if no more clients are editing the document, delete the Yorkie document.
Screenshot 2024-03-12 at 4 31 45 PM
client.detach(doc, { removeIfNotAttached: true });

Why is this needed:

  • To provide users with the flexibility to store document content in a service DB while maintaining document consistency.
@hackerwins hackerwins added the enhancement 🌟 New feature or request label Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement 🌟 New feature or request
Projects
Status: Todo
Development

No branches or pull requests

1 participant