CoffeeScript

Download Report

Transcript CoffeeScript

with SQL
Michael Pace & Jerome Martinez
What is CoffeeScript?
• CoffeeScript is a language that compiles to
JavaScript.
• Therefore, it can be used to interact with
node.js, a server-side, out-of-browser
JavaScript environment.
Project Overview
• We modified the CoffeeScript compiler to
allow for local, embedded SQL commands.
They cannot connect to an external database,
but work as a local data store for your
program running in a node.js environment.
SQL vs. CoffeeScript SQL
SQL
CoffeeScript SQL
•
CREATE DATABASE database_name
•
CONNECT database_name
•
CREATE TABLE table_name
(column_name1 data_type1,
column_name2 data_type2)
•
CREATE TABLE table_name
{column_name_1:data_type_1,
column_name_2:data_type_2}
•
INSERT INTO table_name (column1,
column2) VALUES (value1, value2)
•
INSERT INTO table_name VALUES
{column1:value1, column2:value2}
•
UPDATE table_name SET column1=value1
WHERE some_column=some_value
•
•
DROP TABLE table_name
UPDATE table_name SET
{column1:value1} WHERE some_column
is some_value
•
SELECT column_name1,column_name2
FROM table_name1,table_name2 WHERE
some_column=some_value
•
DROP TABLE table_name
•
SELECT [column_name1,column_name2]
FROM [table_name1,table_name2]
WHERE some_column is some_value
Compiler Overview
• lexer.coffee
– tokenizes code
• rewriter.coffee
– transforms token stream
• grammar.coffee
– generates Jison parser, creates AST
• nodes.coffee
– translation to JavaScript
SQL Tokens Added
•
•
•
•
•
•
•
•
lexer.coffee
CONNECT
CREATE_TABLE
CREATE_DATABASE
INSERT_INTO
SELECT
UPDATE
WHERE
Changes to the Rewriter
• rewriter.coffee
• New method sqlRemoveCall()
Changes to the Grammar
• grammar.coffee
• Expression -> SQLExpression
• Assign -> Assignable = SqlExpression
• SQL grammar starts at line 300
SQL Node Added to AST
• nodes.coffee
• SQL node calls the JavaScript SQLite module
• New class SQLNode
simple.coffee
rec_fact.coffee
Installation
• Details for installing our source code is located
in the readme
Example Code
• Demo files in the demo/ directory
Future Projects
• Asynchronous database file access
• Connecting to remote servers
• Additional SQL commands