linvodb3
linvodb3 copied to clipboard
Store HTML in LimvoDB
I'm looking for a DB storage for an app built on NW.js or Electron, and LinvoDB seems to be suitable.
Long story short: I want to make something like Sublime Text (I don't know exactly how it works, so I will make a guess) · Creating a new TAB, all content inside is store in localStorage/IndexedDB/... · When the file needs to be saved, it stores the content in localStorage and then create the file. · If the file already exists, the localStorage content overwrites it.
You may have question why I'm not using files directly, and it's because the first request: We don't know if the user will save the file, but we don't want to lose all the content if the app is closed.
Searching the web, I find that is bad practice to pass HTML content (is for WYSIWYG editor) through JSON, but I can't think of other solution.. I'd have to use encodeURI and decode when retrieve the data to the #editor or the file saved.
So.. How would you do a «Notepad - Sublime Text» editor using PounchDB, or NeDB, or LimvoDB using Electron/NW.js engine?
I'm using: · Electron · Angular · I don't know yet what DB should I choose.
Thank you!
an advantage with linvodb here is that it's abstract to the storage engine, and you can use anything compatible with leveldown
This means that localStorage/indexedDB/even raw files are all usable, depending on how the storage performs.
In the case you're mentioning, I'd recommend being open-minded about storage
With LinvoDB, you can create a model called "TempFile" or directly "File" and use that.
You can have a dirtyData
field on your object, which contains the last state of the data; this would be saved very often, like 1s after last keystroke.
Then, you can have a function, .flushToDisk()
, which flushes the file to disk when the user actually saves it, and removes dirtyData
.
The benefit of this design is that you can call .save()
as often as you want, and keep what the user is typing secure and saved (in localStorage, indexedDB or whatever you want), and call .flushToDisk()
when the user actually saves to disk
Nice answer, Ivsthi. How is this project different from Angular LocalForage?
I'm also considering PounchDB, for sync (online & offline) storage. How does LinvoDB behaves trying to synchronize data on both sides? (This is more for future feature, but it's wise to build the ground)