Skip to content

inLabFIB/imp-sql

Repository files navigation

IMP SQL

IMP SQL is the implementation of the standard SQL metamodel. More precisely it is inspired in the metamodel of the 92' SQL revision.

This tool focuses on representing 3 basic SQL schema objects: Table, View and Assertion. The 3 united under the concept of a SQLObjectSchema which acts as a container for different SQL objects.

The IMP SQL tool has a core package, where all the domain classes and functionalities are standard SQL, but also has other implementation dependent packages. In this first version of the tool the package sql_server is provided, with functionalities of this concrete implementation of SQL.

What is this library good for?

IMP SQL can be used to parse SQL expressions to generate instances of the metamodel representing SQL objects.These can be analyzed, validated and printed back to SQL.

The following expressions can be parsed to instance the different SQL objects the metamodel accepts:

CREATE TABLE people (
  name varchar(64),
  age int,
  legalTutor varchar(64) NOT NULL,
  CONSTRAINT pk1 PRIMARY KEY (name),
  CONSTRAINT fk1 FOREIGN KEY (legalTutor) REFERENCES people (name)
);

CREATE VIEW adult AS (
  SELECT *
  FROM people AS p
  WHERE p.age >= 18
);

CREATE ASSERTION menorAmbTutor CHECK ( NOT ( EXISTS (
  SELECT * 
  FROM people AS p
  WHERE p.age < 18 AND p.legalTutor IS NULL
)));

Additionally, query expressions can also be parsed with the same available grammar:

SELECT *
FROM people AS p
WHERE p.age < 18
  AND p.legalTutor IS NULL;

Build

Building with ANTLR4

To compile the project for the first time, or whenever we change the grammar files, we need to execute the mvn generate-sources phase.

Indeed, this phase creates the ANTLR4 autogenerated classes to visit the grammar. Hence, we recommend compiling the project with maven.

About

IMP SQL

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors