io.github.rahulrajsonu:native-sql-helper

This library will help developers to map native sql query result to a pojo class

License

License

Categories

Categories

JSON Data Native Development Tools
GroupId

GroupId

io.github.rahulrajsonu
ArtifactId

ArtifactId

native-sql-helper
Last Version

Last Version

1.0
Release Date

Release Date

Type

Type

jar
Description

Description

io.github.rahulrajsonu:native-sql-helper
This library will help developers to map native sql query result to a pojo class
Project URL

Project URL

https://github.com/RAHULRAJSONU/native-sql-helper
Source Code Management

Source Code Management

https://github.com/RAHULRAJSONU/native-sql-helper

Download native-sql-helper

How to add to project

<!-- https://jarcasting.com/artifacts/io.github.rahulrajsonu/native-sql-helper/ -->
<dependency>
    <groupId>io.github.rahulrajsonu</groupId>
    <artifactId>native-sql-helper</artifactId>
    <version>1.0</version>
</dependency>
// https://jarcasting.com/artifacts/io.github.rahulrajsonu/native-sql-helper/
implementation 'io.github.rahulrajsonu:native-sql-helper:1.0'
// https://jarcasting.com/artifacts/io.github.rahulrajsonu/native-sql-helper/
implementation ("io.github.rahulrajsonu:native-sql-helper:1.0")
'io.github.rahulrajsonu:native-sql-helper:jar:1.0'
<dependency org="io.github.rahulrajsonu" name="native-sql-helper" rev="1.0">
  <artifact name="native-sql-helper" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.github.rahulrajsonu', module='native-sql-helper', version='1.0')
)
libraryDependencies += "io.github.rahulrajsonu" % "native-sql-helper" % "1.0"
[io.github.rahulrajsonu/native-sql-helper "1.0"]

Dependencies

test (1)

Group / Artifact Type Version
org.junit.jupiter : junit-jupiter-api jar 5.0.0-M4

Project Modules

There are no modules declared in this project.

native-sql-helper

Native SQL helper is a java library for convenient native SQL querying.

  • (~8KB, no dependencies).

Maven Dependency

<dependency>
    <groupId>io.github.rahulrajsonu</groupId>
    <artifactId>native-sql-helper</artifactId>
    <version>1.0</version>
</dependency>

Gradle Dependency

compile group: 'io.github.rahulrajsonu', name: 'native-sql-helper', version: '1.0'

SBT Dependency

libraryDependencies += "io.github.rahulrajsonu" % "native-sql-helper" % "1.0"

Example

You can use this utility to map your native SQL resultList to a List of Pojo.

class Employee {
  String id;
  String firstName;
  String lastName;
  String email;
  String department;
  Date doj;
  boolean active;
}

class EmployeeRepository {
  @PersistenceContext
  private EntityManager em;
  
  public List<Employee> getActiveEmployeeList(){
    Query queryString = em.createNativeQuery("select firstName, lastName, email from employee where active=1");
    List<Object[]> resultList = queryString.getResultList();
    // build a list of columns (should be in same order as select query)
    String[] columns = {"firstName","lastName","email"};
    List<Employee> response = NativeSQLHelper
            .mapToModel(resultList, Employee.class, columns);
    return response;
  }

}

More interesting features to come...

Versions

Version
1.0