Upload
kai-lu
View
95
Download
1
Embed Size (px)
Citation preview
RagnarDB SQLKAI LU AND PATRICK JENNINGS
Project Goals Create an Object Oriented SQL Querying plugin in Gosu
Interpret Data Definition Files Create Types based on these descriptions Add Object Oriented Functionality to these types Add support similar to that in more common languages Compare to Java Object Oriented Querying Library (jOOQ)
Parsing Recursive descent parsing Top Down Approach Testing for correctness via ANTLR Lexing code into Tokens
Parsing
DDL CreateTable
ColumnDefinition
Constraint
Extracting data we care about A DDL File contains many tables Tables contain many Column Definitions and many Constraints
Type system Metaprogramming
Information from the parser is loaded into the Gosu Typeloader at Compile time
Types for each table are created Methods related to tables can also be invoked statically We use this to support custom query building
Query Construction
At this point, our new classes still don’t do much So we added support for construction of SQL queries Queries can be called off of constructed types statically
Insert instances of types into database SQLConstraint Class describes clauses in SQL statements
Query Functionality Select Statements
Specify Rows returned Join Statements, On statements
Recursive Support for multiple Joins Where Statements
Is In Constraints SQL SubQueries
Is Equal to / Greater, Less than, etc Is Like Boolean Logic For multiple constraints
Order By Limit Clauses
Fine-grain control for complex queries
SELECT name, phone, email, address FROM customers AS contactInfo WHERE country = ‘US’;
WITH RECURSIVE destinations(city, country) AS ( SELECT city, country FROM connections WHERE start = ‘Foster City’ UNION ALL SELECT city, country FROM connections WHERE start = city)SELECT * FROM destinations
SELECT game FROM ign WHERE rating > (SELECT rating FROM ign WHERE game = ‘Tales Of Symphonia’)
SQL Files are now Gosu Types
PresentationQuery1.sql: SELECT * FROM Contacts WHERE Name = ‘Kai Lu’;->var kais = MyQuery.execute()
for(kai in kais){ print(kai.Name) }->Kai Lu
ID Name Email Age1 Patrick Jennings pjennings 192 Kai Lu klu 193 Luca Boasso lboasso ??4 Kyle Moore kmoore ??
Contacts
Query Execution:
Parameterization
@variableName:variableType exposes a parameter of type variableType, called variableName to the plugin
Applications
Moving Forward
Full Set of Data Types (arrays, date/time, XML) Transactions and multiple queries Connection management Cache management Error Handling Resolving the N+1 queries problem