Scenario:
I've a JavaScript based application which uses web sql database to store its data
I've developed a custom entity set.
It has a filter method which accepts string that contains sql query.
for example: People.filter("Name = 'Test' and ...")
My entity sets have two mode in their behaviors, InMemory & NonInMemory
InMemory: filter method will filter the source array in memory, without round trip to db.
NonInMemory: filter method will read the source from db again with new filter.
To have an easier development, I want to make differences of these behaviors from developers transparent.
And I want to make my filter method works on both modes (InMemory & NonInMemory) with the same code.
I've thousands of these filters, which are working fine in .net & sql lite.
and I want to migrate them to JavaScript & web sql as easy as possible.
My question:
Is there any JavaScript library that can handle this situation ?
Which accepts Sql queries and create a JavaScript function as a predicate for me ?
Thanks
i am actually working on an sql-based project for javascript that uses a generated function for the where clause. Part of this is converting the SQL syntax differences to JS where feasable (AND>&&, etc), and the other part is to provide SQL functions to the clauses.The project is not complete and does not aim for 100% or even 80% compatibility, just to allow the most useful sql features and syntax to work in javascript. the where-function making routine below is not a parser or complex AST builder, just a semi-naive yet fast and sufficient string transformer.
it's suppports a wide chunk of where-ish SQL now and should be quite simple to expand upon yourself; not a lot of black magic going on here.
the resulting functions are ideal to filter() an array of objects.
here is a port of the relevant piece of the project, which is quite large, the where-clause builder:
most of the js sql libs out there are somewhat skimpy on WHERE functionality and are hard to expand, hopefully you and others can get some use or inspiration from this. consider it public domain by author, me.