Coder Social home page Coder Social logo

jproggy / snippetory Goto Github PK

View Code? Open in Web Editor NEW
6.0 3.0 3.0 779 KB

A code generation platform for java with intact templates. A sql generator for prepared statements. A fluent API for easy application.

Home Page: https://www.jproggy.org/snippetory/

License: Apache License 2.0

Java 93.76% HTML 2.31% Smarty 0.79% Groovy 2.62% Cypher 0.52%
java sql syntax code-generation intact-templates jdbc jdbctemplate prepared-statements secure-templating groovy javascript multilingual database kotlin html encoding sql-builder sql-query reflection codegen

snippetory's Introduction

A code generation platform for java

Fluent API

Syntaxes.FLUYT.parse("Hello $who").set("who", "world").render(System.out);

Simple Syntax

Locations

$name

Locations can have attributes.

$label(pad="15" pad.fill="."): $name(default="Snippetory")

Regions

$fields{
$name(pad="15"pad.fill="."): $value(number="#.###,##" date="long")    
}$

Regions allow loops or conditions

void renderFields(Map<String, Object> fields, Template fieldsTpl) {
    field.forEach(k, v -> 
        fieldsTpl
            .get("fields")
            .set("name", k)
            .set("value", v)
            .render()
    )
}

Regions have attributes like locations.

$products(delimiter="------------\n"){
...
}$

Comments

/// start with a triple slash

Syntax selector

To keep the template intact there are several syntaxes.

<!-- Syntax:FLUYT_X -->
<nav>
<ul>
  <t:menu>
  <li><a href="$page(enc='url')">$text</a></li>
  </t:menu>
</ul>
</nav>

The tag syntax allowes the IDE to support in closing the tags and keep the overview with code folding...

// Syntax:FLUYT_CC
// $getters{
  public $type get$Name$() {
    return $name$;
  }
// }$

And having valid java code lets the IDE maintain the templates during re-factorings.

SQL module

With the StatementRepository templates produce prepared statements in JDBC

-- $variables{
set :currency = 'EUR';
set :catIds = 17;
-- }$
SELECT products.*
FROM products
LEFT OUTER JOIN prices ON ( 
      products.id = prices.productId 
  AND prices.currency = :currency 
)
WHERE products.id IN (
    SELECT prodCat.product.id
    FROM prodCat
    /*${*/
    WHERE prodCat.categoryId IN (:catIds/*delimiter=', '*/)
    /*}$*/
)

Having prepared variables makes it easy to test the intact statement, a fluent API gives access to the data.

Statement stmt = new SqlContext()
  .uriResolver(UriResolver.resource("org/jproggy/sample"))
  .connections(() -> connection)
  .getRepository("DbAccessRepo.sql")
  .get("statement1");

catIds.forEach(id -> stmt.append("catId", id));
List<Object[]> result = stmt.set("currency", "USD")
  .list(SQL.objects());

So much more

Further information can be found on the homepage or the project blog.

snippetory's People

Contributors

bebertz avatar rotn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  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.