Coder Social home page Coder Social logo

rchibiscus / java-sql-generator Goto Github PK

View Code? Open in Web Editor NEW

This project forked from stazz/java-sql-generator

0.0 1.0 0.0 643 KB

A framework to generate syntactically correct SQL statements in a typesafe, easy, and uniform way (without StringBuilders).

java-sql-generator's Introduction

The java-sql-generator is a framework to generate syntactically correct SQL statements with Java language. It provides uniform, typesafe, and (reasonably) easy way to create SQL statements using provided API's. It is specifically designed to handle even really complex SQL clauses. In fact, the API's were designed by looking at SQL 99 BNF ( http://savage.net.au/SQL/sql-99.bnf.html ), and creating the corresponding Java API. However, there are many things omitted, changed, or varied from automated BNF conversion, so that API would remain usable and simple.

Please notice that this framework depends on API Typeable POJOs (ATP) project ( http://github.com/stazz/api-typeable-pojos ). Currently APT is in public maven repo, so you won't need to download it separately, if you are using Maven.

Currently there is support for data querying (SELECT), modification (INSERT, UPDATE, DELETE), data definition (CREATE), data manipulation (ALTER).

Please see the tests of the implementation project on how to use the java-sql-generator framework. Typical usecase for simple queries would be:

// Create or acquire vendor
SQLVendor vendor = SQLVendorProvider.createVendor( MyVendorClass.class );
SQLVendor vendor = ...;

/*
  Creating query:
  SELECT value
  FROM table
  WHERE table.value = 5
  ORDER BY 1 ASC
*/

BooleanFactory b = vendor.getBooleanFactory();
ColumnsFactory c = vendor.getColumnsFactory();
LiteralFactory l = vendor.getLiteralFactory();
TableReferenceFactory t = vendor.getTableReferenceFactory();

QueryExpression query = vendor.getQueryFactory().simpleQueryBuilder()
  .select( "value" )
  .from( t.tableName( "table" ) )
  .where( b.eq( c.colName( "table", "value" ), l.n(5) ) )
  .orderByAsc( "1" )
  .createExpression();

// The following two statements produce equivalent SQL statement string
String sqlString = vendor.toString( query );
String sqlStirng2 = query.toString( );

java-sql-generator's People

Contributors

eskatos avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.