Skip to content

evanwht/simple-sql-builder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple SQL Builders

Light weight, zero dependency java.sql.PreparedStatement builders.

Installation

You can find this library on maven central

Maven

<dependency>
  <groupId>com.evanwht</groupId>
  <artifactId>simple-sql-builder</artifactId>
  <version>1.1</version>
</dependency>

gradle

compile 'com.evanwht:simple-sql-builder:1.1' 

Usage

You can build simple SELECT, DELETE, UPDATE, and INSERT statements. To interact with the builders and make sure the sql statements they generate will work correctly, table definitions need to be created. The easiest way is to create a enum that implements the Column interface.

enum MyDBColumns implements Column {
    ID("id", Types.INTEGER),
    NUM("num", Types.INTEGER),
    NAME("name", Types.VARCHAR);
    
    // implement methods
}

INSERT

OptionalLong insertedId = new InsertBuilder<>()
    .table("my_table")
    .value(MyDBColumns.NUM, 42)
    .value(MyDBColumns.NAME, "DeepThought")
    .execute(connection);

SELECT

Optional<String> name = new SelectBuilder<>(rs -> rs.getString(MyDBColumns.NAME))
    .table("my_table")
    .select(MyDBColumns.NAME)
    .where(MyDBColumns.ID, 1)
    .where(MyDBColumns.NUM, 42)
    .getOne(connection);

License

MIT

About

Light weight java.sql.PreparedStatement builders

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages