sql-streams

Painless low level JDBC abstraction using the Java 8 Stream API

License

License

MIT
GroupId

GroupId

me.lucko
ArtifactId

ArtifactId

sql-streams
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

sql-streams
Painless low level JDBC abstraction using the Java 8 Stream API
Project URL

Project URL

https://github.com/lucko/sql-streams
Source Code Management

Source Code Management

https://github.com/lucko/sql-streams

Download sql-streams

How to add to project

<!-- https://jarcasting.com/artifacts/me.lucko/sql-streams/ -->
<dependency>
    <groupId>me.lucko</groupId>
    <artifactId>sql-streams</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/me.lucko/sql-streams/
implementation 'me.lucko:sql-streams:1.0.0'
// https://jarcasting.com/artifacts/me.lucko/sql-streams/
implementation ("me.lucko:sql-streams:1.0.0")
'me.lucko:sql-streams:jar:1.0.0'
<dependency org="me.lucko" name="sql-streams" rev="1.0.0">
  <artifact name="sql-streams" type="jar" />
</dependency>
@Grapes(
@Grab(group='me.lucko', module='sql-streams', version='1.0.0')
)
libraryDependencies += "me.lucko" % "sql-streams" % "1.0.0"
[me.lucko/sql-streams "1.0.0"]

Dependencies

test (4)

Group / Artifact Type Version
junit : junit jar 4.12
org.xerial : sqlite-jdbc jar 3.21.0.1
com.h2database : h2 jar 1.4.196
org.postgresql : postgresql jar 42.1.4

Project Modules

There are no modules declared in this project.

sql-streams

Codeship Status for bendem/sql-streams

sql-streams is a tool for the people that don't need or want to use an ORM but don't want to deal with the JDBC API either. It provides a light abstraction over JDBC without ever making it inaccessible.

Features

  • Simple setup if you already have a Connection or a DataSource available
  • Fluent API
  • ResultSet is abstracted to a Stream
  • Classes that can be closed are AutoCloseable
  • SQLException are wrapped into UncheckedSqlException
  • Doesn't try to hide the JDBC primitives, they are never further than a method call away
  • Automatic type deduction with the with method

Getting started

To get started, all you need to do is to add sql-streams to your dependencies:

<dependency>
    <groupId>be.bendem</groupId>
    <artifactId>sql-streams</artifactId>
    <version>[current version]</version>
</dependency>
compile 'be.bendem:sql-streams:[current version]'

Once it is done, you can create an instance of Sql using one of the two connect methods.

try (Sql sql = Sql.connect(datasource)) {
    Optional<String> userEmail = sql
        .first("select email from users where user_id = ?")
        .with(userId);
}

If you are using spring-boot, checkout sql-streams-spring!

Development

You will need maven to compile and install this library

mvn install

In addition to the SQLite and H2 tests, you can run the tests with PostgreSQL by providing a jdbc connection url:

PGURL=jdbc:postgresql:test mvn test
# or with user and password if not using peer authentication
PGURL=jdbc:postgresql://localhost/test PGUSER=test PGPASSWORD=test mvn test

Versions

Version
1.0.0