Fluent ORM and Models
Persist data with Vapor's Fluent ORM.
What Is Fluent?
Fluent is Vapor's ORM. It maps Swift classes to database rows, supporting PostgreSQL, MySQL, SQLite, and MongoDB through a single API. You write Swift; Fluent writes SQL.
import Fluent
import VaporDefining a Model
A Fluent model is a final class conforming to Model and usually Content. It declares a schema (table name) and an @ID property for the primary key.
final class Planet: Model, Content {
static let schema = "planets"
@ID(key: .id)
var id: UUID?
init() {}
}All lessons in this course
- Routing and Request Handling
- Content and JSON Encoding
- Fluent ORM and Models
- Middleware and Authentication