4

I'm working on a small project where I'm going to read some parameters from a SQLite database. The data is generated from a Linux server running a C code. I then want to create a script using JavaScript to fetch the data from the database. I've tried with alasql.js but it takes very long time (~1 minute) before I get the list with the parameters from two tables.

SELECT sensors.id, sensors.sensorname, sensors.sensornumber, information.sensorvalue, information.timestamp FROM sensors INNER JOIN information ON sensors.id=information.sensorid 

I've been reading about IndexedDB but seems like it only works with JavaScript but not with C-code. Please, correct me if I'm wrong. The clue here is that I want a database that supports writing to database from C-code and reading from database from JavaScript. The database can be read either from file:// schema or an IP address.

Would appreciate any help regarding this problem. Thanks!

4
  • Is this a browser application or node.js? Commented Apr 16, 2015 at 19:59
  • @agershun it is a browser application. Any idea how to boost up the performance? Commented Apr 16, 2015 at 20:22
  • 1
    SQLite has a complicated format (sqlite.org/fileformat2.html) and it takes a time to read it in JavaScript. Can you replace database with plain text file? This would be faster to read it and reindex it in memory with JS.If this approach it applicable, please, write me on email. Commented Apr 17, 2015 at 2:30
  • Another idea: you can write simple server on node.js with native support of SQLite and then provide requested records in JSON format with ajax to your application (like in this article dalelane.co.uk/blog/?p=3152) Commented Apr 17, 2015 at 3:13

1 Answer 1

4

Unfortunately, SQLite internal file format is complicated to fast parsing with JavaScript. One of the reasons, that the only browser side library which can read it is SQL.js and it is relatively slow, because it can not read data by selected pages from the database file, but only the whole file.

One of the options: you can switch from SQLite format to CSV or TSV plain tet formats, which can be eaily and quickly send to the browser and be parsed with jQuery.CSV, PapaParse, AlaSQL or any other CSV parsing libraries, like:

alasql('SELECT * FROM TSV("mydata.txt",{headers:true})',[],function(data){
       // data
});

Another alternative: you can write simple server on node.js with native support of SQLite and then provide requested records in JSON format with ajax to your application (like in this article)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.