Skip to content

SQL util for Java using HikariCP, to make querying SQL in Java easier.

License

Notifications You must be signed in to change notification settings

justEli/Esqueleto

Repository files navigation

Esqueleto

Description

SQL util for Java using HikariCP, to make querying SQL in Java easier.

Maven

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

<dependencies>
    <dependency>
        <groupId>com.github.JustEli.Esqueleto</groupId>
        <artifactId>esqueleto-core</artifactId>
        <version>VERSION</version>
    </dependency>
    <dependency>
        <groupId>ADAPTER_PACKAGE</groupId>
        <artifactId>ADAPTER_ID</artifactId>
        <version>ADAPTER_VERSION</version>
    </dependency>
</dependencies>

Adapters

Adapter Works? Esqueleto Version Adapter Version
MariaDB ✅ Fully latest (always tested) 2.7.7 (Maven)
MySQL ❌ ResultSet closed
SQLite ❌ Can't select
PostgreSQL ❌ ResultSet closed
MS SQL Server ❌ Untested
H2 ❌ Untested

Examples

Open connection

Esqueleto sql = Esqueleto.create(config -> {
    config.setDriver(MariaDBDriver.class);
    // CREATE DATABASE esqueleto_test;
    config.setDatabase("esqueleto_test");
    // CREATE USER 'esqueleto'@'localhost' IDENTIFIED BY 'dAQ5g61NT';
    // GRANT ALL PRIVILEGES ON esqueleto_test.* TO 'esqueleto'@'localhost';
    config.setUsername("esqueleto");
    config.setPassword("dAQ5g61NT");
}).start();

Update

Returns the inserted id of the signature

UUID playerUuid = ...;
byte[] signature = ...;

Optional<Integer> signatureId = sql.statement(
    "INSERT INTO Signature (playerId, signature) VALUES ((SELECT id FROM Player WHERE uniqueId = ?), ?)"
).bind(
    playerUuid,
    signature
).update().complete(data -> data.next()? data.getInt("id") : null);
Company company = ...;
int transactionAmount = ...;

sql.statement("""
    UPDATE Company SET profit = profit + ?
    WHERE id = ?
    """
).bind(
    transactionAmount,
    company.getId()
).update().push();

Select

Player player = ...;

Optional<Long> discordId = sql.statement(
    "SELECT discordId FROM Player WHERE username = ? LIMIT 1"
).bind(
    player.getUsername()
).query().complete(results -> {
    return results.next()? results.get("discordId") : null;
});

Close

sql.close();

About

SQL util for Java using HikariCP, to make querying SQL in Java easier.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Languages