0Pricing
Swift Academy · Lesson

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 Vapor

Defining 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

  1. Routing and Request Handling
  2. Content and JSON Encoding
  3. Fluent ORM and Models
  4. Middleware and Authentication
← Back to Swift Academy