Git Product home page Git Product logo

jsqb's Introduction

SQL Query Builder

Stop to lost time writing repeated SQL queries and let Java SQL Query Builder do the job for you. It's simple, fast and lightweight. You don't need to make a connection with a database.

1. Installation

For default installation, see Releases section to download the .jar file and add it to the path of your project.

1.1. Installation with Maven

To install with maven, you can use the Jitpack for that.

Step 1. Add the JitPack repository to your build file

<repositories>
    ...
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>

Step 2. Add the dependency

<dependencies>
    ...
    <dependency>
        <groupId>com.github.derickfelix</groupId>
        <artifactId>jsqb</artifactId>
        <version>LATEST</version>
    </dependency>
</dependencies>

If the project doesn't have any GitHub Releases you can use the short commit hash or 'master-SNAPSHOT' as the version. Check the Jitpack page for more details.

2. SELECT Statement

2.1. Basic SELECT statement

Usage:

public class Usage {
    public static void main(String[] args)
    {
        Jsqb jsqb = new Jsqb();
        String sql = jsqb.select("users").write();
    
        System.out.println(sql);
    }
}

Output:

SELECT users.* FROM users

2.2. SELECT with Specific Fields

Usage:

public class Usage {
    public static void main(String[] args)
    {
        Jsqb jsqb = new Jsqb();
        String sql = jsqb.select("users", "id", "name", "email").write();
    
        System.out.println(sql);
    }
}

Output:

SELECT users.id, users.name, users.email FROM users

2.2. Aliased SELECT statement

The same of the previous one but with more information.

Usage:

public class Usage {
    public static void main(String[] args)
    {
        Jsqb jsqb = new Jsqb();
        String sql = jsqb.select("users", "id as userId", "name as username", "email as receiver").write();
    
        System.out.println(sql);
    }
}

Output:

SELECT users.id as userId, users.name as username, users.email as receiver FROM users

3. INNER JOIN statement

3.1. Simple Inner join

The innerJoin() method expects the tableName, and the on detail, and the fields parameter is optional. This method is described as: innerJoin(String tableName, String on, String... fields).

Usage:

public class Usage {
    public static void main(String[] args)
    {
        Jsqb jsqb = new Jsqb();
        String sql = jsqb.select("users", "id", "name", "email")
                             .innerJoin("roles", "roles.id = users.role_id", "name", "level")
                             .write();
    
        System.out.println(sql);
    }
}

Output:

SELECT users.id, users.name, users.email, roles.name, roles.level FROM users 
INNER JOIN roles on roles.id = users.role_id

4. Author

Derick Felix

5. License

Java SQL Query Builder is licensed under the Apache license.

Copyright 2018 derickfelix.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
 
     http://www.apache.org/licenses/LICENSE-2.0
 
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

jsqb's People

Contributors

thederickff avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

str4ng3r

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.