I have an application that use WebSQL. I want to support IndexedDB too (For Browsers without WebSql support). Is there any libary that use sql-syntax but works with indexedDB / LocalStorage in background?
I don't want to change all my querys and functions.
All libraries i found uses IndexedDb syntax and support WebSql. (Not what I need).
Thanks :)
WebSQL Database is a relational database access system, whereas IndexedDB is an indexed table system. Don't start working with IndexedDB, relying on your assumptions from other types of databases. Instead, you should read the docs carefully.
Web SQL is a web page API for storing or managing the data in databases that can be queried using a variant of SQL like creating databases, opening the transaction, creating tables, inserting values to tables, deleting values, and reading data.
The W3C has announced that the Web SQL database is a deprecated local storage specification so web developer should not use this technology any more. indexeddb is an alternative for web SQL data base and more effective than older technologies.
You can try Alasql JavaScript SQL database library. It supports all important SQL statements and can work with IndexedDB with SQL syntax as well.
Here is an example:
<script src='alasql.min.js'></script>
<script>
var cityData = [{city:"Redmond", population:57530},
{city:"Atlanta",population:447841},
{city:"San Francisco", population:837442}];
// Create IndexdDB database and fill it with data from array
alasql('CREATE INDEXEDDB DATABASE IF NOT EXISTS geo;\
ATTACH INDEXEDDB DATABASE geo; \
USE geo; \
DROP TABLE IF EXISTS cities; \
CREATE TABLE cities; \
SELECT * INTO cities FROM ?', [cityData], function(){
// Select data from IndexedDB
alasql('SELECT COLUMN * FROM cities WHERE population > 100000 ORDER BY city DESC',
[],function(res){
document.write('Big cities: ', res.join(','));
});
});
</script>
You can play with this example in jsFiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With