Giter VIP home page Giter VIP logo

sql-builder's Introduction

SQL Builder

A dynamic SQL builder for Java language.

Build Status

Examples

Some usage examples: Select

QueryBuilder query = new QueryBuilder().select()
                                       .column("s.name")
                                       .column("count(s.impediments) AS total_impediments")
                                       .from()
                                       .table("sprint s")
                                       .groupBy()
                                       .column("s.name")
                                       .having()
                                       .column("total_impediments > 5")

The output is:

SELECT
    s.name,
    count(s.impediments) AS total_impediemnts
FROM
    sprint s
GROUP BY
    s.name
HAVING
    total_impediemnts > 5

Delete

DeleteQuery query = new DeleteQuery("account a").addWhere("a.id > 666")
                                                .addWhere("a.creation_date > '2013-01-01'");

The output is:

DELETE
FROM
    account a
WHERE
    a.id > 666
    AND a.creation_date > '2013-01-01'

Update

UpdateQuery query = new UpdateQuery("employee e").set("e.salary", "50000")
                                                 .addWhere("e.age > 40")
                                                 .addWhere("e.genre = 'female'");

The output is:

UPDATE
    employee e
SET
    e.salary = '50000'
WHERE
    e.age > 40
    AND e.genre = 'female'

Insert

InsertQuery query = new InsertQuery("persons").columns("id", "name", "age")
                                              .values(1, "foo", 30)
                                              .values(2, "bar", 23)
                                              .values(3, "hello", 54)
                                              .values(4, "world", 19);

The output is:

INSERT INTO
    persons (id, name, age)
VALUES
    (1, 'foo', 30),
    (2, 'bar', 23),
    (3, 'hello', 54),
    (4, 'world', 19)

Usage

To use this library, add this dependency on your pom.xml:

<dependency>
    <groupId>com.github.jonathanhds</groupId>
    <artifactId>sql-builder</artifactId>
    <version>1.1</version>
</dependency>

sql-builder's People

Contributors

dependabot[bot] avatar jonathanhds avatar llorllale 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.