- Notifications
You must be signed in to change notification settings - Fork1
A simpe SQL parser and pretend DB written in JavaScript
maciakl/jQuery-SQL-Emulator
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
JSQ is a simple SQL parser and pretend-database written in JavaScript with jQuery. It can be used to teach students simple SELECT SQL statements without access to a real database. The database here is basically a JSON object.
Here is the general idea: I want to be able to show how SQL works without the need of setting up a database. JSQ is purely client side app that will run just about anywhere. You set up a mock database as a JSON file (let's call itdb.json) formated like this:
{ "kitchen" : [{"id": 1, "name": "chair"}, {"id": 2, "name": "table"}, {"id": 3, "name": "sink"}, {"id": 4, "name": "stool"}]}Put it somewhere on your server. Then you can just do:
var sql = 'select id, name from kitchen';var db = 'db.json';JSQ.query(sql, db, function(result){ document.write(result);});Seeexample.html for a more detailed example of how to use it with a live form.
You can read about implementation details and inspiration for this project inthis old blog post.
Things that work:
- Simple select statements:
select firstname, lastname from students where gpa > 3.0
Things that do not work:
- The
select *idiom is not implemented - No aggregation functions like
sumorcount - No
order byclause - No joins of any kind (single table operations only)
- Some syntax is problematic (eg
gpa > 2.0works butgpa>2.0does not)
JSQ depends on the following components:
- jQuery Framework
- jQuery.string Plugin by David E. Still
Development time dependencies are:
You can easily install these dependencies usingBower by going to the project directory:
bower installThis will create acomponents folder in that directory with all the dependencies. If you do this, thenexample.html should just work. If you don't want to use Bower then simply download latest jQuery and Dot String plugin and modify the links in the example file.
The example file makes a json request so you need a server. If you don't have one, just rungrunt from the project directory. You will need node.js and grunt.js to do this. Added bonus is that grunt will lint the Javascript for you.
About
A simpe SQL parser and pretend DB written in JavaScript
Resources
Uh oh!
There was an error while loading.Please reload this page.