Skip to content

Basic SQLParser, Parses the SQL query into an object. You can then apply the query results to a JS dataset.

License

Notifications You must be signed in to change notification settings

hazlema/SQLParse

Repository files navigation

SQLParse

🚧 Under Heavy Development 🚧

Basic JS SQLParser, creates an object that contains the parsed SQL(ish) query. You can then apply the query to a dataset.

Only supports select, where and orderby.

Functions

Some Functions are now chainable, marked with 🔗

Function Description
hasQuery Is the query set?
hasSelect Does the query have a Select statement
hasWhere Does the query have a Where statement
hasOrderBy Does the query have an OrderBy statement
get Return the parsed query
getSelect Return the Select of the parsed query
getWhere Return the Where of the parsed query
getOrderBy Return the OrderBy of the parsed query
isWhere Return true or false if the data matches the Where statement
renderTree Render the parsed query
🔗 setQuery Shortcut to set the query property
🔗 sort Sort the dataset
🔗 where Apply the Where query to the dataset
🔗 select Apply the Select query to the dataset
🔗 update Apply the updates to the dataset
results Returns an array of results
table Returns a table of results

You only need to initialize the SQLParse object once

To change the current query simply set the value of the query property:

object.query = "where new=true"

Quick examples

let parser = new SQLParse('where (name=/matthew/i and color = "Blue")');

Single where (returns true):

parser.isWhere({name:"matthew", color="Blue"});

Sort the DataSet

parser.sort([dataset]).results();

Where the DataSet

parser.where([dataset]).results();

Select the DataSet

parser.select([dataset]).results();

Do it all

parser.sort([dataset]).where().select().results()

As you can see in the above query, you only need to set the dataset for the first function in the chain.

The chain is smart, for instance if there is no Where statement in your query, your chain processes will skip over that part.

Update the DataSet (3 examples)

parser.query = "[query]";
parser.update({key: value}, [dataset]);
parser.setQuery([query]).update({key: value}, [dataset]);
parser.query = "[query]";
parser.sort([dataset]).update({key: value}).results();
  • If the query is not specified the last query is used. Look at test-update.js for an example.
  • The same rules for chained functions apply, the dataset to use only needs to be set in the first link in the chain.

Test Results

About

Basic SQLParser, Parses the SQL query into an object. You can then apply the query results to a JS dataset.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published