Jaloquent

JitPack GitHub Packages Coverage

Jaloquent is an Eloquent-style active-record ORM layer for Java, built on the EzFramework Java Query Builder. It provides a consistent, fluent API for both SQL (JDBC) and flat-map stores, inspired by Laravel’s Eloquent ORM.


Features

  • Dual-store routing — the same model class works against an in-memory flat-map store and any JDBC data source; switching is transparent
  • Active-record helpersmodel.save(repo), Model.find(repo, id), model.delete(repo) with no boilerplate
  • Type-safe attribute accessgetAs(key, Class<T>) with built-in Integer ↔ Long ↔ String coercion
  • Mass-assignment protectionfill() (permissive) and update() (strict) respect setFillable / setGuarded declarations; id is always block-listed
  • Query builder — fluent WHERE, ORDER BY, LIMIT with ? bind parameters — SQL injection is structurally impossible
  • Four relation typesHasOne, HasMany, BelongsTo, BelongsToMany with lazy loading, sync, attach, detach, and detachAll
  • Laravel-style factoriesFactory<T> + HasFactory marker for fixture generation backed by Jaker
  • Database transactions — atomic multi-step operations via TransactionalJdbcStore; try-with-resources handle or lambda callback with automatic commit/rollback
  • SLF4J + Micrometer — opt-in observability with zero mandatory dependencies

Quick start

1. Add Jaloquent via JitPack:

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

<dependency>
  <groupId>com.github.EzFramework</groupId>
  <artifactId>jaloquent</artifactId>
  <version>1.1.0</version>
</dependency>

2. Define a model:

public class Player extends Model {
    public Player(String id) { super(id); }

    public String getName()       { return getAs("name", String.class, ""); }
    public void   setName(String n) { set("name", n); }

    public int  getCoins()        { return getAs("coins", Integer.class, 0); }
    public void setCoins(int c)   { set("coins", c); }
}

3. Register a SQL table (optional — skip for flat-map stores):

TableRegistry.register("players", "player_data", Map.of(
    "id",     "VARCHAR(36) PRIMARY KEY",
    "name",   "VARCHAR(64)",
    "coins",  "INT"
));

4. Create a repository and persist:

ModelRepository<Player> repo = new ModelRepository<>(
    myStore,    // implements DataStore (+ JdbcStore for SQL)
    "players",
    (id, data) -> { Player p = new Player(id); p.fromMap(data); return p; }
);

Player p = new Player(UUID.randomUUID().toString());
p.setName("Alice");
p.setCoins(500);
p.save(repo);

Optional<Player> found = repo.find(p.getId());

Documentation

Page What it covers
Installation Maven, Gradle, JitPack, requirements
Models Defining models, attributes, mass-assignment
Repositories Setup, TableRegistry, CRUD, bulk operations
Queries Query builder — filters, ordering, limits
Relations HasOne, HasMany, BelongsTo, BelongsToMany
Factories Generating test fixtures with Factory<T>
Configuration Logging and metrics via JaloquentConfig
Transactions Atomic multi-step operations, commit/rollback
Exceptions Error hierarchy and handling patterns
API Reference Full public-method tables for every class