I'm looking for ways to use jsGrid (http://js-grid.com) as local application.
I've found basic.html in demos folder from git-project and I noticed that changes made to the example datagrid are not committing (after refreshing a local copy of basic.html all changes revert to initial values). As far as I understand changes made to the table are in memory and main script doesn't save them to db.js where datasource (json-dictionary clients) is located. And as confirmation I found that implementation of updatingClient-function in db.js is empty (due to obvious in-memory realization).
Questions I want to ask:
1) How could I make this application to use external but local datasource? Should it be some kind of this pseudocode in db.js:
db.clients = csv2json('clients.csv') (assuming there is an additional jquery-plugin to do this task) ? Are there any more convenient approaches?
2) If the first question is reasonable how should I implement the updateClient function considering using by multiple users simultaneously? Is it possible?
3) I need some kind of time logging of actions performed on the datagrid. Should it be implemented by binding certain elements to log-functions on main page via click events? If so, how could I get time stamps from these functions?
If you install xampp, you will have apache, PHP and MySQL - all local.
Otherwise, you can install sqlite or Codernitydb (better), which are local databases that do not require Internet access.
Related
I am creating an app that get data from the server then save it and work locally with sqlite.
I want to initialize my application with data loaded only after the first installation, saved to sqlite and then loaded from database.
For that i want to create a method that save the data locally, how to make sure this method runs only after the first time the user install the app.
I think that the easier way to do this is to check, at every application run, if your database contains a certain value in a config table: if isn't present, populate the db, otherwise do nothing and continue execution.
In this way you could avoid to write platform specific code (native) since you're doing everything from the js layer.
Obviously I'm supposing that you're already using sqlite in Cordova, and that you can execute sql query/insert from js.
HTML5 appcache is a good way to cache resources in the client side and make them available when the user goes offline. I was playing around with this technology for sometime now, and it works pretty good so far with static resources like html, css, js, images etc.
Now I have come to a situation where I have the need to integrate some php functionality into my application. For the sake of simplicity lets say my show_tasks.php does this,
<?php
// Print the list of task names from the database.
printMyTasks();
?>
So I have put cached this page inside my myCache.appcache file like this,
CACHE MANIFEST
#v1.0
show_tasks.php
Now the issue is this.
When the user accesses this page for the first time (given he is
online), the browser caches the html page along with the list of tasks
those were there at that moment. But after that, even when he is
online, it does not connect to the database and fetch the latest data.
Instead it always shows the cached version which was cached in the
first run.
I understand that in order to update the cache in the client side, a change must be done to the show_tasks.php file itself (not the data it manipulates) and also the myCache.appcache file should be updated. (In my case, a change to the show_tasks.php won't happen)
I am looking for a solution so that my application works in a way such that,
If the user is online, read the tasks from database and show them.
(Don't show the cached version)
If the user is offline, show the cached version, but also with the
most recently updated data. (The list of tasks fetched when he
accessed it online the last time)
I have looked into Using appcache with php & database question too. But I am wondering if there is another way of achieving this. (Probably using some client side functionality) Obviously I am willing to use Javascript/Jquery.
What will be a good approach to handle this scenario?
I work on a web app which store projects data. Data are saved in a couchDb database A. The app pull and push data with a local pouchDb database B, which is sync with A.
So the app can also work offline. When user has connection back, changes made on localDb B during offline time are sent to A using a classic replication.
I store 1 document per project in couchDb, it is a big JSON object with lot of data (project todos, collaborators, advancements, risks, problems, etc...).
It is working like a charm, but I have some problems, and it seems I use pouchDb in wrong way. Situation example:
User A is offline and he adds a todo on project 1.
User B is online and he adds a new collaborator on project 1.
User B changes are pushed to couchDb by the automatic sync.
The project 1 _rev has been incremented.
User B pulls its own changes from couchDb, because the app downloads all documents on any couchDb changes detected. Weird... Idk how to prevent that. But the app still work fine so it's not a big problem.
User A gets its connection back.
User A changes are ignored because of older _rev. But the user did a modification on a different project property, can couchDb detect that himself and merge with newer _rev ?
I clearly see my problem is I'm using 1 document per project. I could use thousands documents to store each properties of each project and my problem woudn't happens, but it seems quite weird: To retrieve all data of a project I would fully scan my database, check document type (collaborator, todos, ...?), and check if the document is linked to the project by adding a new _projectId property to any document.
Currently I just have to request one document, which contains all project data, then I manipulate my JSON easily. It's quite convenient to handle.
How to manage this ? A project may contains averagely 10 to 10 000 properties that multiple users can edit being online or offline.
But the user did a modification on a different project property, can couchDb detect that himself and merge with newer _rev ?
PouchDB/CouchDB conflict handling is described in the PouchDB guide: http://pouchdb.com/guides/conflicts.html
the app downloads all documents on any couchDb changes detected. Weird... Idk how to prevent that.
This is standard PouchDB/CouchDB behavior - you asked it to sync the whole database, so it synced the whole database. :) You can prevent it by using filtered-replication: http://pouchdb.com/api.html#filtered-replication.
How to manage this ? A project may contains averagely 10 to 10 000 properties that multiple users can edit being online or offline.
It really really depends on your data, how frequently it may change, what the unique identifier of a single "property" is... Storing 10,000 separate documents in PouchDB/CouchDB is not a crazy idea, though, and may help you out when it comes to conflicts, since only those individual documents can ever be in conflict.
In general, I'd recommend you read the guide to conflict resolution as described above and review your options. There's also a plugin that may help you with conflict resolution: https://github.com/jo/pouch-resolve-conflicts
I am constructing a standalone application that is comprised of HTML, CSS and JS files. The data that is being used by the application is being loaded from an XML file.
I, however, require the application to use a local database - something that would allow me to load, create and edit the data in this database using Javascript. Then package up the application and send it on (I am using webapp-xul-wrapper for this).
Could anybody give me some advice on how I could achieve this? The majority of solutions I have looked at use local storage or only keep the db table data for that particular session or require server side code.
To clarify, my application has a settings page that I would like to allow to edit my data and then keep that data persistent so that when the application is opened again the data is intact. Furthermore, if I was to send the application to someone else - that data would also be intact. Ideally my app would take its data from a physical file that could be passed around.
I hope this question makes sense!
Many thanks,
G.
I actually ended up using a packager called TideSDK (http://www.tidesdk.org/) which supports SQLLite out of the box and also seems to render my applications layout much clearer.
Many thanks!
I want to make some sort of website on a USB stick which opens in a browser. The HTML file should be able to read a (sql-)database in the same folder using javascript. It's a little application for me. These are my files:
USB stick:
-- start.html
-- database.sql
HTML5 offers "local storage" and it works perfectly. But with this method I can't access a local, already existing database on the stick. The browser creates a separate, emtpy database and saves it not on the stick. I don't need to write datasets.
Is there a different method to read databases? Thanks!
You can use sql.js, which is a SQLite converted to JavaScript. You'll have to provide your own import/export functions though and, naturally, you can't export to filesystem in JS, but since you only intend to read, that won't be a problem.
You are not going to be able to get the web browser to run a sql query. The best thing you could do is have it load data using ajax from the local file. It is not possible to save the updated data base to the local file system however.
You could have the javascript read comma separated data or the data could be stored in xml or json.
If you are wishing to save data however I believe a desktop application is needed
If it is just for reading, it is possible to just read and parse a file using javascript. But I wouldn't use an SQL file, but rather a file containing JSON instead. I don't think there are JavaScript libaries that can read SQL, and it won't be an easy job to write one.
Mind though, that even if you manage to find one, all of the file's contents will be read into memory, and that it is not possible to write the file.
Since you want a local running database application, I would very sincerely advise you not to use HTML and Javascript, but rather Java or any native language that can read the database and do some proper memory management. You may stick to HTML/JS for the GUI, if you want to, but you may find it just as easy to leave HTML out of it altogether.
What you want now, is very uncommon. Database applications tend to have a backend, and websites tend not to be run from a USB stick.
The problem is that local storage is local to the system the browser is running on because it's local to the browser not from where the files originated.
This means you'll have to deliver the data to the browser for it to store the data locally. Right now your data is located on your stick.
You have a couple of options:
1. Deliver the data to the browser to create your local storage database via javascript.
2. Use Rob W's answer and supply a portable browser (good idea Rob!)
I've made no assumptions how the data is stored in your .sql file. If it's actually SQL, you're out of luck. Localstorage is not a sql database.
Good Article on the basics of local storage in HTML5
http://diveintohtml5.info/storage.html