Skip to main content
Kit provides a Laravel/Eloquent-inspired fluent API for working with database models, making common CRUD operations simple and intuitive.

Entity Structure

Kit uses SeaORM entities under the hood. When you run kit db:sync, two files are generated for each table:
  1. Auto-generated entity (src/models/entities/{table}.rs) - SeaORM entity definition, regenerated on sync
  2. User model (src/models/{table}.rs) - Your custom code with the fluent API, never overwritten

Generating Models

Use the db:sync command to generate models from your database:
The --regenerate-models flag will overwrite your custom model files. Use with caution if you’ve added custom methods.

Eloquent-like Fluent API

The generated models provide a fluent, chainable API similar to Laravel’s Eloquent.

Querying Records

Use Model::query() to start a fluent query builder:

Creating Records

Use Model::create() to get a fluent builder for creating new records:

Updating Records

Chain setters on an existing model and call update():

Deleting Records

Call delete() on a model instance:

Complete Example

Here’s a complete CRUD controller using the fluent API:

Model and ModelMut Traits

The fluent API is built on top of two core traits that you can also use directly:

The Model Trait

Provides read-only operations on the Entity:
Implementing kit::database::Model also enables Route Model Binding, allowing you to use Model types directly as handler parameters for automatic database lookup.

The ModelMut Trait

Provides write operations:

Working with ActiveModel

For advanced use cases, you can work directly with SeaORM’s ActiveModel:

ActiveValue States

Model Relationships

Define relationships in your model file:

Loading Relationships

API Summary

Fluent API (on Model)

QueryBuilder Methods

Entity Trait Methods