Preloaded local database for Javascript (maybe?)

I recently saw articles about creating and using HTML5 and local Db. I also saw some examples of Javascript connection strings for existing Access Db backends. I am interested in finding a way to create Db, preload it using records and use a web application to connect and read Db. For example, I created many standalone Tcl applications on Windows that read Sqlite Db files. In fact, the application (.exe file) and the Db file are located next to each other in the folder and function like any other Db application, except without using servers.

I would like to be able to do the same, but with a web application (.html) and a Db file. Does anyone know if this is possible? As an example, I wanted to create a language application that runs in any browser, with preloaded words stored in the backend. So there will be two files, a web application and a db file.

Any suggestions or links to resources would be really appreciated. The only thing I could think of was connecting to Access via OLE via Javascript, however I need Db, which is multi-platform, like Sqlite.

Thanks,

Dfm

+4
source share
2 answers

Your web application, its local database, and the "primed" data should all start with something, so I assume that all this happens during a direct connection to the web server. When this first strike hits, you:

  • Provide the page and associated code.
  • In your JavaScript, check for a database.
    • Exists? No primer required. Do nothing, sync, etc.
    • Does not exist? Build it and deliver the source data. If this happens slowly, you can give the user a friendly warning: "Setup, please wait." Depending on how you click all this data, you may even show a progress bar: "Initializing the database: 10%" ...
  • There is no step 3.

After the installation is complete, this application can be completely local - there is no need for a network connection - if you encode it without assuming non-local resources.

References:

+3
source

You can access the already created sqlite db file through javascript. Take a look at the Database File Location field of this link http://code.google.com/apis/gears/api_database.html

I know this is for Google Gears, but Gears uses SQLite, and the location is still applied without Gears and only using the sqlite db file.

For example, I used the "SQLite Manager" add-in for Firefox to create a sqlite db file on my local machine. Then I copied this file to C: \ Users \\ AppData \ Local \ Google \ Chrome \ User Data \ Default \ databases \ file__0

I was able to access the file using JavaScript in Google Chrome:

var db = null; try { if (window.openDatabase) { db = openDatabase("mydbfile.sqlite", "1.0", "HTML5 Database API example", 200000); .... 

You have to be careful with the file name in Chrome, as it automatically calls each sqlite db id number. For example, I had to rename the sqlite db file name to 14 in order to read it in JavaScript in a browser. As soon as I did this, he worked as a champion, and I was able to access all the tables, data, etc.

+3
source

Source: https://habr.com/ru/post/1315313/


All Articles