With SQL Michael Pace & Jerome Martinez. What is CoffeeScript? CoffeeScript is a language that...

14
with SQL Michael Pace & Jerome Martinez

Transcript of With SQL Michael Pace & Jerome Martinez. What is CoffeeScript? CoffeeScript is a language that...

Page 1: 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 SQL

Michael Pace & Jerome Martinez

Page 2: With SQL Michael Pace & Jerome Martinez. What is CoffeeScript? CoffeeScript is a language that compiles to JavaScript. Therefore, it can be used to interact.

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.

Page 3: With SQL Michael Pace & Jerome Martinez. What is CoffeeScript? CoffeeScript is a language that compiles to JavaScript. Therefore, it can be used to interact.

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.

Page 4: With SQL Michael Pace & Jerome Martinez. What is CoffeeScript? CoffeeScript is a language that compiles to JavaScript. Therefore, it can be used to interact.

SQL vs. CoffeeScript SQLSQL

• CREATE DATABASE database_name

• CREATE TABLE table_name (column_name1 data_type1, column_name2 data_type2)

• INSERT INTO table_name (column1, column2) VALUES (value1, value2)

• UPDATE table_name SET column1=value1 WHERE some_column=some_value

• DROP TABLE table_name

• SELECT column_name1,column_name2 FROM table_name1,table_name2 WHERE some_column=some_value

CoffeeScript SQL

• CONNECT database_name

• CREATE TABLE table_name {column_name_1:data_type_1, column_name_2:data_type_2}

• INSERT INTO table_name VALUES {column1:value1, column2:value2}

• UPDATE table_name SET {column1:value1} WHERE some_column is some_value

• DROP TABLE table_name

• SELECT [column_name1,column_name2] FROM [table_name1,table_name2] WHERE some_column is some_value

Page 5: With SQL Michael Pace & Jerome Martinez. What is CoffeeScript? CoffeeScript is a language that compiles to JavaScript. Therefore, it can be used to interact.

Compiler Overview

• lexer.coffee– tokenizes code

• rewriter.coffee– transforms token stream

• grammar.coffee– generates Jison parser, creates AST

• nodes.coffee– translation to JavaScript

Page 6: With SQL Michael Pace & Jerome Martinez. What is CoffeeScript? CoffeeScript is a language that compiles to JavaScript. Therefore, it can be used to interact.

SQL Tokens Added

• lexer.coffee• CONNECT• CREATE_TABLE• CREATE_DATABASE• INSERT_INTO• SELECT• UPDATE• WHERE

Page 7: With SQL Michael Pace & Jerome Martinez. What is CoffeeScript? CoffeeScript is a language that compiles to JavaScript. Therefore, it can be used to interact.

Changes to the Rewriter

• rewriter.coffee• New method sqlRemoveCall()

Page 8: With SQL Michael Pace & Jerome Martinez. What is CoffeeScript? CoffeeScript is a language that compiles to JavaScript. Therefore, it can be used to interact.

Changes to the Grammar

• grammar.coffee• Expression -> SQLExpression• Assign -> Assignable = SqlExpression

• SQL grammar starts at line 300

Page 9: With SQL Michael Pace & Jerome Martinez. What is CoffeeScript? CoffeeScript is a language that compiles to JavaScript. Therefore, it can be used to interact.

SQL Node Added to AST

• nodes.coffee• SQL node calls the JavaScript SQLite module• New class SQLNode

Page 10: With SQL Michael Pace & Jerome Martinez. What is CoffeeScript? CoffeeScript is a language that compiles to JavaScript. Therefore, it can be used to interact.

simple.coffee

Page 11: With SQL Michael Pace & Jerome Martinez. What is CoffeeScript? CoffeeScript is a language that compiles to JavaScript. Therefore, it can be used to interact.

rec_fact.coffee

Page 12: With SQL Michael Pace & Jerome Martinez. What is CoffeeScript? CoffeeScript is a language that compiles to JavaScript. Therefore, it can be used to interact.

Installation

• Details for installing our source code is located in the readme

Page 13: With SQL Michael Pace & Jerome Martinez. What is CoffeeScript? CoffeeScript is a language that compiles to JavaScript. Therefore, it can be used to interact.

Example Code

• Demo files in the demo/ directory

Page 14: With SQL Michael Pace & Jerome Martinez. What is CoffeeScript? CoffeeScript is a language that compiles to JavaScript. Therefore, it can be used to interact.

Future Projects

• Asynchronous database file access• Connecting to remote servers• Additional SQL commands