I am using Phonegap 1.3.0, and want to develop an app which uses local storage. Some googling brought me to sqlite, but i have had no success in implementing it in my app.
https://github.com/davibe/Phonegap-SQLitePlugin
I tried this link but i am really not sure what this lawnchair.js is all about.
Sqlite is my priority but I can try other options too. I also tried window.opendatabase() but it doesnt work in my app.
Thanks in advance!
Lawnchair is a wrapper over many storage methods. There is localstorage, sqlite, blackberry specific, and others.
There are many adapters in lawnchair to store stuff. http://westcoastlogic.com/lawnchair/adapters/
The way lawnchair works is, if an adapter is specified, it will use that, or if no adapter is specified and if the code of all adapters is appended to lawnchair.js file, then lawnchair checks which one to use in the order of they are appended and picks the first one it finds suitable.
What makes lawnchair easy to use is that we don't have to deal with sql syntaxs (assuming u want to use sqlite adapter.) You just store and retrieve your data in JSON by
table.save(key:"obj", name:{a:"aaaa", b:"bbbb"})
table.get(key:"obj", function(ob){
//callback
})
and internally lawnchair will save data in sqlite. You can use any adapter, but all u have to use is the above syntax. easy. lawnchair is a powerful wrapper over many storage options. check it out
Related
I am working on a custom framework which will be used by developers. I am saving some data locally inside my framework for that I am thinking to use UserDefaults but I want to know:
Is it the best method to do so?
If the app UserDefaults are cleared then will it clear my frameworks data also?
I want to know how can I store local data in ios framework. What is the best solution for this?
I am confused about it can anyone help?
It depends on the data you want to store.
If your goal is to keep some settings for your framework (e.g. whether some features should be enabled or not) then UserDefaults will do.
If you want to store user's data (or anything you can get from the server) then you should probably consider using CoreData, which is a native iOS/macOS/tvOS persistent storage.
You can also use Realm database, but it's not a good idea to use it in frameworks, since it will be added to any application which will use your framework (and the developers probably won't be happy about this).
Regarding you questions:
It depends, see above
Yes
Userdefaults is great but at times it turns into a mess if you have alot of information that needs to be stored. Specially the fact that you would need to manage a key/value relationship throughout the app and usually the keys end up being more than 10 plus ..
Just a suggestion but why not use CoreData to manage models and store data in sqlite db on device. When the framework is loaded you can check if the data exists if not then fetch it.
I would suggest using the functionality provided by apple natively rather than going for 3rd party solutions like Realm, with 3rd party you would need to upgrade to their latest version in order to make things work fine.
Please read these to clear any confusion.
https://cocoacasts.com/what-is-the-difference-between-core-data-and-sqlite/
Tutorial on using Coredata:
https://www.raywenderlich.com/7569-getting-started-with-core-data-tutorial
Recently started with electron. Can any one please help me with the database selection. It seems like there is no straight forward choice for it.
Suggest a database for medium size project.
In Electron app, you can use the database of your choice :
https://github.com/louischatriot/nedb
https://github.com/pouchdb/pouchdb
http://lokijs.org
https://github.com/kripken/sql.js
https://github.com/pubkey/rxdb
https://github.com/amark/gun
https://github.com/typicode/lowdb
https://github.com/google/leveldb
According to your purpose, a single JSON file can be used as a database.
You can use CouchDB, which is the non-sql database, in that you can store data in JSON format, they have inbuilt sync functionality, that means, you just need to store data locally in HTML storage provider and CouchDB will automatically sync that with the server.
I just wanted to do a quick sanity check with StackOverflow to confirm my suspicion. I'm creating an app and was tempted to use FMDB in Swift to store some data.I am treating this data as public in the sense that I assume it can be tampered with (and thus untrusted). This is because, after all, unlike a web app, this app runs on a user's device and thus they can access the .sql file and alter the database.
If I wanted to store information like if a user purchased something, unlocked certain weapons, or other data that I do not want to be altered in any way, I should not use a local database on the user's device.
Would you say this is correct and safe to proceed under this assumption? If I was looking to use the database to persist something important that took place, what would be a good approach? encryption with the key in the app, or maybe a hash or something?
If you want to secure your database, FMDB includes hooks for SQLCipher, which you have to obtain separately. See the various FMDB Encryption Methods that you can use once you have SQLCipher included in your project.
I can't seem to locate a built in mechanism to store user settings. I was hoping that electron provided a standard method for storing user settings across all desktop platforms. If there isn't a precedent for this I can implement it myself, I just didn't want to jump to a custom solution immediately. Research online is pretty sparse in this area. Thanks!
Each platform has different default locations for different kinds of data. So, if you want to store data in default locations based on platform, check out app.getPath(name)
It retrieves a path to a special directory or file associated with name.
You can also use it to differentiate between data the user wants to save, and data your application saves that you don't want to clutter up users directories.
Or if you just want to store files reletive to a specific path you can use the
app.setPath(name,path)
I've faced this particular problem with my Electron app and this post inspired me to write an NPM module called electron-json-storage.
This module allows to easily write/read JSON to/from app.getPath('userData'):
const storage = require('electron-json-storage');
// Write
storage.set('foobar', { foo: 'bar' }).then(function() {
// Read
storage.get('foobar').then(function(object) {
console.log(object.foo);
// will print "bar"
});
});
Electron doesn't give you anything out of the box for this. However, Electron does give you a method for getting the idiomatic location of storing user data in a cross platform way via the app.getPath API.
I'd say the 3 most common ways to do this are:
localStorage (or any HTML5 storage API)
flat JSON file (this is what I do, and I use electron-store for it)
embedded database like IndexedDB, neDB, or sqlite
Which one you choose will depend on your app's needs. If you only need to access this data in the renderer process, then I'd just use localStorage. Most of the time it seems you need to access the data in both the main and renderer, so a JSON file makes sense. If you're dealing with lots of data or complex querying, then maybe a database makes sense. I wrote about this more in detail here.
How about LocalStorage? If you need to access these settings from the browser process, you probably need to write your own (or just use a node.js library that implements this)
The best way that I have found is to store it in a simple file as JSON. The problem is that if you store that JSON in the app dir, then when you update the app, it will get wiped out. So you want to put it in the default directory for user settings for the current operating system. LUCKILY!!!!! There is a library for node developers that will help you find the userdata directory. The module is called appdirectory, and I have used it several times. It is extremely easy to use.
See APPDIRECTORY HERE
One could store data in cookies; Electron has a mechanism for it (https://electronjs.org/docs/api/cookies) and the cookies can be retrieved in the browser (Angular: https://docs.angularjs.org/api/ngCookies/service/$cookies, React/Other: https://github.com/reactivestack/cookies)
I was able to get it working with Angularjs.
i am developing application in blackberry which use database.
i want to make generalize class for that just like DBadepter class in android which have all operation to perform for database. if any one have solution for that then send to me.
thanx.
you can also used persistence store for database check this link
it is easy compare to sqlite