Reputation: 803
I'm about to dive into a new mobile project, to be more specific a mobile TCG (Trading Card Game) Deckbuilder app. As it's about to be my first mobile app, I've done some research and came across Phonegap. I've done a couple of node-based web apps, so it seems right down my alley.
I started searching for how to store any data on a phone and found out there are 3 possibilities:
LocalStorageStore, seems out of the question for the complexity of my app. So it's between MemoryStore and WebSqlStore.
What would suit my project? And how complex could you go?
So the idea is to have a "big" json file with all existing cards:
{
id: xx,
name: 'name'
manacost: xx,
attack: xx,
defence: xx,
effects: [
'lorem ipsum',
'lorem ipsum'
],
image: '/img/cards/xx.png'
}
So to save a deck I suppose I could go for:
Wouldn't this be too heavy on the memory? And yet again, what database system would be suited for this?
Upvotes: 0
Views: 51
Reputation: 75
you can use SQLite to save your data. It's very proper way to save your data in table format so that you can get required data using sql query. When you are using huge data at that time, sometimes it's difficult to handle this with session or localStorage. So I suggest you to use SQLite. As I mention below example, you will get an idea for creating DB.
<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript">
var db = openDatabase('mydatabase', '1.0', 'My DB', 2 * 1024 * 1024);
db.transaction(function (tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS USER (id unique, name)');
tx.executeSql('INSERT INTO USER (id, name) VALUES (1, "Ram")');
tx.executeSql('INSERT INTO USER (id, name) VALUES (2, "Amay")');
});
db.transaction(function (tx) {
tx.executeSql('SELECT * FROM USER WHERE id=?', [1], function (tx, results) {
var len = results.rows.length, i;
for (i = 0; i < len; i++){
var data = "<p><b>" + results.rows.item(i).name + "</b></p>";
document.querySelector('#custName').innerHTML += data;
}
}, null);
});
</script>
</head>
<body>
<div id="custName">USER NAME</div>
</body>
</html>
Upvotes: 3
Reputation: 3101
The best SQLite plugin is this one:
https://github.com/litehelpers/Cordova-sqlite-storage
or the special versions of this plugin, found here:
https://github.com/litehelpers/Cordova-sqlite-storage#other-versions
If your app is based on JSON, you should have a look at PouchDB, it is a NoSQL Database which you can use on top of the cordova sqlite plugin:
Upvotes: 2