Using existing database in Firefox OS app - firefox-os

I don't know much about FirefoxOS hence this question.
I have an android app that ships with already prepared data saved in SQLite database. In the runtime the app copies that db to the device storage and uses it for reading and writing data. This is much more efficient than creating empty DB file and inserting data when the app first starts(e.g from JSON).
I was wondering how can I achieve the same thing in Firefox OS? Is there any way I can create IndexedDB, fill it with data and then add it to the app package as an asset?

Unfortunately this behavior is not yet supported. As Fabrice Desré mentioned in bugzilla, some of the files to achieve this behaviour is specific to gaia apps, which gecko does not have access at the moment.
By now, you will have to stick with the less efficient method (depending on the size of your db, the difference isn't that big).
Hope I was able to help,
cheers

Related

NodeJS storing large object - JSON file vs Database

I am loading a few big JSON data from 3rd party API on server startup and write them into .JSON files (150mb json files), loading it into an object whenever I need to use it.
The thing is, I am not sure this is the right and efficient way to do so. Should I use a database instead? If yes, could you mention which one to use?
Thanks.
glad to answer your question.
Modern databases are already able to keep up with large file sizes, so in this case size would not be an issue.
However, the issue regarding performance is that it still depends on the usage and purpose of the application.
For example, sometimes the application might require content caching, in this case most databases already have this function built-in, however, there are also applications where this won't apply.
This issue also discusses the comparison of disk storage and database storage, there are lots of good answers in there, I hope it will help.

Sync multiple devices with Core Data

I have a coredata app that I would love to be able to share the same data with multiple devices, possibly with iCloud/cloud kit. I am not sure where to start, or how to go about it? The only thing I can think of, but still not sure how to do, would be to sync the SQLite files with iCloud? Not sure if thats a good idea or not? I just recently converted my app over to swift 3 and iOS10 core data code. The only way I am able to share data between devices currently is thru iTunes files sharing.
For whatever reason this topic is hard to find modern info on.
Core Data doesn't have support for this. Except for the built-in iCloud sync, but that's deprecated as of iOS 10.
You could use CloudKit to sync data, but you'll have to write your own code to convert between Core Data's persistent store and CloudKit's online store. It's not impossible but it's certainly not automatic.
Syncing the SQLite file is not a good idea unless you really want to corrupt the data.

Node.js / CouchDB: Use .json files instead of a database + Version Control

I'd like to just use .json files to store data, rather than using a database. Many simple sites have little data, and reading/writing to a file (that can be added to version control) seems adequate, and eliminates the need for database versioning / deployment logistics.
npm: node-store
Here's one way to do it, yet I'd need to implement all kinds of query functionality.
I'm really unfamiliar with CouchDB. From the little I've read, it looks like it might use files to store the JSON data, but it might use some kind of disk storage. Can someone shed some light on this?
Does CouchDB store its JSON in text-based files that can be added to version control (git)?
Does anyone know of another text-based storage system with some query functionality?
CouchDB is a full fledged database. The value that gives you above simply using file based storage is additional indexing. Ie., if you do file based then you can either only do key based look ups (the file name) or build your own secondary indexing methodology (symlinks or whatever). Now you're in the database building business instead of the app building business, which is silly because your entire premise seems to be simplicity and focusing on your app.
Also, keep in mind that when you have many (even just 2) people causing writes to your file(s), then you're going to run into either file system locking problems or users overwriting one another.
You're correct though, if you only have a few pieces of information then a single JSON file - basically a config file - is far easier than a database. Especially if people are only reading from the file.
Also, keep in mind that there are Database-as-a-Service solutions that remove the need for DIY install/configure/maintenance/administration. One of them is Cloudant which is based on CouchDB, is API compatible, contributes back, etc. (I work at Cloudant).
Does anyone know of another text-based storage system with some query functionality?
You can use ueberDB module with Dirty file storage.
As far as I remember, this storage just appends your data to the same text file over and over again, so if you really have small dataset, it'll work just fine.
If you data will grow too much, you can always change storage while using the same module.

Can HTML5 localStorage in Cordova/Phonegap app be synced to iCloud?

I have a Phonegap/Cordova app that runs on iOS. It saves it's data into HTML5 localStorage.
I'm trying to work out if it's possible to sync the localStorage data (using iCloud) to other iOS devices, and even OS X.
From what I can see, in iOS localStorage is actually implemented as a SQLite database, which (when using Phonegap/Cordova) is written to the app's Documents directory:
Documents/Backups/localstorage.appdata.db
I also understand that there are three main ways of storing data in iCloud:
Key/Value storage
UIDocument / NSDocument
Core Data
I know I can't use the Key/Value iCloud storage method, because I have more than 1MB of data to store, and the limitation is 1MB per app with that method.
This question, I believe is talking about the UIDocument method, and asks if it is possible to store a SQLite db file in iCloud using that method. The answer is no because the database may become corrupted.
So that really leaves the Core Data method.
So my question is - would this work? Could I sync the localStorage.db file to iCloud using Core Data?
I've never used Core Data and don't know much about it. I'm just wondering if it would be possible, or if there is something else I don't understand.
Are there any other ways to sync localStorage data between iOS devices or OS X ?
The answer unfortunatly appears to be no, Core Data cannot be used with HTML5 localStorage
Core Data can not be used with SQLite databases other than ones created with Core Data. If you try to, you get this error in XCode:
SQLite error code:1, 'no such table: Z_METADATA'
This is explained the Core Data docs:
https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreData/Articles/cdFAQ.html#//apple_ref/doc/uid/TP40001802-SW2
Although Core Data supports SQLite as one of its persistent store
types, the database format is private. You cannot create a SQLite
database using native SQLite API and use it directly with Core Data
(nor should you manipulate an existing Core Data SQLite store using
native SQLite API)
I still want to solve this issue though. I'm thinking of creating a Javascript API that mirrors the localStorage API. This would be a phonegap plugin that can call objective-c code, and effectively write it's changes to a Core Data database. The Core Data database should then be able to be synced to iCloud.
If it works, I'll come back and update this answer.

Can CouchDB actually be used for a desktop application?

I'm hoping someone can validate or correct my conclusions here.
I'm looking into writing a small side project. I want to create a desktop application for taking notes that will synchronise to a web-server so that multiple installations can be kept in step and data shared and also so that it can be accessed via a browser if necessary.
I've kind of been half-listening to the noises about CouchDB and I've heard mention of "offline functionality", of desktop-couchdb and of moves to utilise its ability to handle intermittent communications to enable distributed applications in the mobile market. This all led me to believe that it might be an interesting option to look at for providing my data storage and also handling my synchronisation needs, but after spending some time looking around for info on how to get started my conclusion is that I've got completely the wrong end of the stick and the reality is that:
There's no way of packaging up a CouchDB instance, distributing it as part of a desktop application and running it in the context of that application to provide local storage and synchronisation to a central database.
Am I correct here? If so is there any technology out there that does this sort of thing or am I left just rolling my own local storage and maybe still using CouchDB on the server?
Update (2012/05): check out the new TouchDB projects from Couchbase if you are targeting Mac OS X and/or iOS or Android. These actually use SQLite under the hood (at least for now) but can replicate to/from a "real" CouchDB server. Another clientside alternative that is finally starting to mature is PouchDB, which runs in IndexedDB capable browser engines. Using these or using them to inspire similar port to another desktop platform is now becoming a better-trod path.
Original answer:
There's no way of packaging up a
CouchDB instance, distributing it as
part of a desktop application and
running it in the context of that
application to provide local storage
and synchronisation to a central
database.
At this point in time, your statement is practically correct although it is possible to include CouchDB in an app — for an example see CouchDBX.app which is a thin wrapper around a prefixed bundle of CouchDB and all its dependencies.
The easiest way to build a CouchDB app is to assume that the user will already have a CouchDB server running. This is easier than it sounds, especially with Couchone's hosting or a prebuilt app like CouchDBX on OS X or DesktopCouch on Ubuntu. This latter is especially interesting, because if I understand correctly it is included by default with Ubuntu these days, and automatically spins up a CouchDB server per-user when you query its port via D-Bus. Something similar could (and should) be done on OS X using launchd and Bonjour.
So as you write, you either would design your app to store data in a local format and optionally sync with a CouchDB service you provide or you'd have to build and bundle all of Erlang, SpiderMonkey and CouchDB together with your app along with some scripts to make sure it was running when needed. This is possible but obviously neither of these are ideal, and believe me you're not the only one wanting a simpler solution for desktop-oriented apps!

Resources