PikaORM
Documentation
Get Started
Install, define a bean, run your first queries.
CRUD
Create, read, update, and delete with the active record API.
Querying
Filtering, ordering, joins, and aggregates.
Migrations
Define and evolve your schema in code.
Relationships
Load related records without N+1.
Cheat Sheet
Every operation at a glance.
Sample Code
Todo.java
// ActiveRecord style classes map to tables, e.g. `todos`
public class Todo extends PikaBean {
private String title;
private String description;
private Boolean completed = false;
public Todo() {}
public void setTitle(String title) { this.title = title; }
public void setDescription(String description) { this.description = description; }
// etc...
// A standard typed entry point for queries against Todos
public static PikaClassFinder<Todo> find() {
return find(Todo.class);
}
// simple validation mechanism
@Override
protected void validation() {
require("title");
}
}
PikaORM orm = new PikaORM("jdbc:sqlite:app.db") // connect to a database
.makeDefaultORM() // make this the standard connection
.withMigrations(new AppMigrations()) // migrations keep your schema up to date
.applyMigrations();
// PikaBeans support simple CRUD
Todo todo = new Todo();
todo.setTitle("Read the docs");
todo.setDescription("Finish the PikaORM guide");
todo.saveOrThrow();
// A nice fluent API for querying
Todo first = Todo.find().byId(1);
PikaList<Todo> active = Todo.find()
.where("completed = :done", "done", false)
.fetchList(); // convert to a list for in-memory work
// Drop down to raw SQL when you want to
PikaList<Todo> rows = orm.select("SELECT * FROM todos", Todo.class).fetchList();