GithubHelp home page GithubHelp logo

jell's Introduction

jell

Jell is a micro-ORM for Java. It allows you to easily execute SQL in Java, as well as automatically mapping parameters from an object and query results back to a specific class. If you don't specify a class, it will map to a dynamic object.

Maven

You can get Jell from Maven Central.

<dependency>
    <groupId>com.noelherrick</groupId>
    <artifactId>jell</artifactId>
    <version>0.1.1</version>
</dependency>

Examples

Creating a jell instance

A new Jell instance is created by passing in a JDBC connection.

Connection conn = DriverManager.getConnection(url, username, password);

Jell jell = new Jell(conn);

Querying

ParamClass is a simple POJO with the fields "number" and "string".

ParamClass param = new ParamClass("a", 2);

String sql = "select 1 as number, 'b' as str where 'a' = @string and 2 = @number";

Collection<ParamClass> results = jell.query(sql, ParamClass.class, param);

Executing

If you have a simple SQL statement, executing is simple:

jell.execute("create table basic_post (id int primary key, title varchar(50) not null)");

Batch inserts

If you have a bunch of inserts, this is simple as well.

List<ParamClass> pojos = new ArrayList<>();

for (int i = 0; i < 1_000_000; i++)
{
    pojos.add(new ParamClass("a", i));
}

jell.executeBatch("insert into basic_post values (@number, @string)", pojos);

Hashes

I wanted something similar to dynamic objects in .NET, but Java does not help me here, so if you don't specify a class to map query results to, it will give you a map-like object.

Collection<Dyno> dynos1 = jell.query("select * from basic_post limit 10", false);

for (Dyno dyno : dynos1) {
    System.out.println(dyno.str("title"));
}

The origin

Whenever I start a .NET project that uses the database, I will almost always fall back to Dapper. It reduces the friction of using an RDBMS in C# code. The standard ADO.NET (.NET's JDBC) API is verbose and painful. With Dapper, I only need to create an ADO.NET connection and I can start writing SQL. Queries are automatically to the class or primitive you specify. Dapper is incredibly near the speed of using ADO.NET, so I choose it over other ORM's.

I wanted something similar for Java, so I built this.

Limitations

Java has several limitations that preclude me from writing a full Dapper replacement in the language.

  1. Java does not have reified generics (or type filters). I must do some reflection magic and hope it works. Unlike C#, I cannot guarantee at compile time that your passed-in class has a parameter-less constructor.
  2. Java lacks the dynamic object. This disallows both dynamic parameter objects and dynamic result objects. I most often use the former.
  3. Java has no viable replacement for extension methods. This means we have to create a separate object using the connection, instead of using a static method like Dapper does.

The name

So you know the .NET library, Dapper. Well, what makes you dapper, at least in the 90s and the 00s? Gel, of course! And since it's a Java library, it's jell!

jell's People

Contributors

noelherrick avatar static-max 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.