I want to execute queries against a local SQLite file, from JavaScript. How can this be done?
By local, I mean a .sqlite file on the user's computer. I do not need storage for an application, so suggestions about WebSQL are not helpful.
The use-case is, I have many local SQLite files that I use as a database for other applications. I am trying to build a Chrome Extension that lets me query the SQLite files so I can see data contents without having to use my SQLlite workbench app, which sucks.
An extension would not be able to do that. While you can "upload" a file to an extension, it would not retain access to the file on disk; it would be just a snapshot at the moment of an upload.
An app, however, can. With chrome.filesystem API, you can request read or read/write access to a file, and retain the resulting entry to query it again later without dialogs to the user.
Of course, it's up to your JS code to actually read the database. There is no API for that, you need to use a library.
Related
I'm developing Chrome Extension that runs on my_webpage.com and request user to log in to see the web page. So I need to store password somewhere locally, first I used local storage but the problem is that it won't load data on my_webpage.com when data is saved localy in settings. Is there any other option to read/write data locay with Chrome Extension?
chrome.storage API was created specifically for that purpose.
It's available both to extension scripts (e.g. background) and content scripts.
Note though that this storage is not considered secure (not that there are alternatives that are secure, besides using chrome.identity to store OAuth tokens)
for saving the username or password two things can help u
create database and save values in tables.
write data to file in json format and read from file to load data
Is there any flat file database system that works well with javascript such as one in JSON format or similar. I have heard about mongodb, couchdb and others but it seems whole setup of it must be installed on the computer.
Of course, I can't use sqlite beause I think I won't be able manipulate it via javascript and I don't want to use any server-side language for my small apps.
I searched on google as well. Basically I am just looking for flat file database system that I can put in javascript app's folder (meaning portable database and app) and be able to use it anywhere, for example on some other computer without having to install any dependencies ? Does such portable flat file database exist out there ?
How about PouchDB? It's intended for web apps that cache data offline.
I am trying to build a web application to replace the functionality of an older desktop economics program. That program is essentially a calculation engine built on top of a Microsoft access database. The inputs and results are all stored on a series of tables. To offer compatibility to the legacy users, I want to have the ability for users to connect to their older, local access databases and upload them into the web app.
The approach I was contemplating was to have a page that allowed the user to select the database they wanted from their local machine and then have the schema and the data for each table sent to the web application. I don't really want to upload the whole file -- I just want to extract the relevant data.
I have done some research and I have looked into the HTML File API. One shortcoming is that the API does not expose the file path of a selected file so there does not seem to be a way to pass that to the connection string necessary to connect to the database using ODBC or ADO.
In summary my basic question is: How can I get the contents of a user's local database into a web application only using the browser?
You will have to upload the whole file to the server first. You can do your manipulations on the server to save only the relevant part and delete the rest... For security reasons Javascript is not able to read file's content from the local user's machine.
A suggestion - you can upload the file to server, read and print the relevant data as JSON or XML format, then delete the file and use all the data in your ajax response on the client's browser.
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
I want to develop an web application that can be served without web server. I mean, via file:///... in a web browser. The application will use HTML5 and Javascript. Also , I would like to add a SQLite with the data to be presented in the application. The database will be static so a read-only access is enough. I don't want a HTML5 local storage solution because the SQLite database is already created and must be load from "server".
I don't find any solution. A pseudocode example may be the following one:
var db = load ("file:///path/to/my/database/file.sqlite");
db.execute ("SELECT * FROM DATABASE");
// Show items
load from the system files, I think this is not posible due to security reasons.
chek this online tool to manage local data storage at: http://wdbengine.sourceforge.net