/SKILL.md
Guide for using Vapor's Fluent ORM framework in Swift server-side applications
npx skillsauth add thepianokid/vapor-fluent-skill vapor-fluentInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Fluent is an ORM framework for Swift used with the Vapor web framework. It leverages Swift's strong type system to provide a type-safe interface for database operations. Instead of writing raw queries, you define model types that represent database structures and use them for CRUD operations.
Use this skill when:
@ID, @Field, @Parent, @Children, etc.)For a new project, use vapor new and answer "yes" to including Fluent. For an existing project, add the Fluent package and a database driver to Package.swift:
// Package dependencies
.package(url: "https://github.com/vapor/fluent.git", from: "4.0.0"),
.package(url: "https://github.com/vapor/fluent-<db>-driver.git", from: "<version>"),
// Target dependencies
.target(name: "App", dependencies: [
.product(name: "Fluent", package: "fluent"),
.product(name: "Fluent<Db>Driver", package: "fluent-<db>-driver"),
.product(name: "Vapor", package: "vapor"),
]),
In configure.swift, import Fluent and the driver, then configure the database connection.
PostgreSQL (recommended):
import Fluent
import FluentPostgresDriver
app.databases.use(
.postgres(
configuration: .init(
hostname: "localhost",
username: "vapor",
password: "vapor",
database: "vapor",
tls: .disable
)
),
as: .psql
)
SQLite (good for prototyping):
import Fluent
import FluentSQLiteDriver
// File-based
app.databases.use(.sqlite(.file("db.sqlite")), as: .sqlite)
// In-memory (ephemeral, useful for testing)
app.databases.use(.sqlite(.memory), as: .sqlite)
MySQL / MariaDB:
import Fluent
import FluentMySQLDriver
app.databases.use(.mysql(
hostname: "localhost",
username: "vapor",
password: "vapor",
database: "vapor"
), as: .mysql)
MongoDB:
import Fluent
import FluentMongoDriver
try app.databases.use(.mongo(connectionString: "<connection string>"), as: .mongo)
PostgreSQL, MySQL, and MongoDB also support connection string URLs:
try app.databases.use(.postgres(url: "<connection string>"), as: .psql)
Create model classes conforming to Model. Mark them final for performance. Every model needs:
schema property (table/collection name, snake_case and plural)@ID fieldinit()final class Galaxy: Model, Content {
static let schema = "galaxies"
@ID(key: .id)
var id: UUID?
@Field(key: "name")
var name: String
init() { }
init(id: UUID? = nil, name: String) {
self.id = id
self.name = name
}
}
Key property wrappers for fields:
@ID(key: .id) -- unique identifier, use UUID? by default@Field(key: "db_column") -- required stored field@OptionalField(key: "db_column") -- optional stored field@Parent(key: "foreign_key_id") -- belongs-to relation (stores a foreign key)@Children(for: \.$parentField) -- has-many relation (inverse of @Parent)@Siblings(...) -- many-to-many relation via a pivot table@Timestamp(key: "created_at", on: .create) -- auto-managed timestampAdd Content conformance to return models directly from route handlers.
One-to-many (Parent/Children):
On the child model, add a @Parent field:
final class Star: Model, Content {
static let schema = "stars"
@ID(key: .id)
var id: UUID?
@Field(key: "name")
var name: String
@Parent(key: "galaxy_id")
var galaxy: Galaxy
init() { }
init(id: UUID? = nil, name: String, galaxyID: UUID) {
self.id = id
self.name = name
self.$galaxy.id = galaxyID
}
}
On the parent model, add a @Children property:
// Add to Galaxy model
@Children(for: \.$galaxy)
var stars: [Star]
Note: Access the underlying property wrapper with $ prefix (e.g., self.$galaxy.id = galaxyID).
Create migrations conforming to AsyncMigration to set up database schemas. The prepare method creates/modifies the schema, and revert undoes those changes.
struct CreateGalaxy: AsyncMigration {
func prepare(on database: Database) async throws {
try await database.schema("galaxies")
.id()
.field("name", .string)
.create()
}
func revert(on database: Database) async throws {
try await database.schema("galaxies").delete()
}
}
For models with foreign keys, add a .references constraint:
struct CreateStar: AsyncMigration {
func prepare(on database: Database) async throws {
try await database.schema("stars")
.id()
.field("name", .string)
.field("galaxy_id", .uuid, .references("galaxies", "id"))
.create()
}
func revert(on database: Database) async throws {
try await database.schema("stars").delete()
}
}
Register migrations in configure.swift in dependency order (parent tables first):
app.migrations.add(CreateGalaxy())
app.migrations.add(CreateStar())
Run migrations from the command line:
swift run App migrate
For in-memory SQLite databases, auto-migrate on startup:
try await app.autoMigrate()
Create:
app.post("galaxies") { req async throws -> Galaxy in
let galaxy = try req.content.decode(Galaxy.self)
try await galaxy.create(on: req.db)
return galaxy
}
Read all:
app.get("galaxies") { req async throws in
try await Galaxy.query(on: req.db).all()
}
Read one by ID:
app.get("galaxies", ":id") { req async throws -> Galaxy in
guard let galaxy = try await Galaxy.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
}
return galaxy
}
Update:
app.put("galaxies", ":id") { req async throws -> Galaxy in
guard let galaxy = try await Galaxy.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
}
let updated = try req.content.decode(Galaxy.self)
galaxy.name = updated.name
try await galaxy.save(on: req.db)
return galaxy
}
Delete:
app.delete("galaxies", ":id") { req async throws -> HTTPStatus in
guard let galaxy = try await Galaxy.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
}
try await galaxy.delete(on: req.db)
return .noContent
}
Use .with(\.$relation) on the query builder to load related models:
app.get("galaxies") { req async throws in
try await Galaxy.query(on: req.db).with(\.$stars).all()
}
This returns galaxies with their stars nested in the response:
[
{
"id": "...",
"name": "Milky Way",
"stars": [
{ "id": "...", "name": "Sun", "galaxy": { "id": "..." } }
]
}
]
To see the generated SQL statements in the console, set the log level to debug in configure.swift:
app.logger.logLevel = .debug
final.init() { }.snake_case and plural names for schema values (e.g., "galaxies", "star_tags").snake_case (e.g., "galaxy_id").$ prefix to access the underlying property wrapper (e.g., $galaxy.id).Content conformance to models you want to return directly from route handlers.development
Maintainer-only workflow for handling GitHub Secret Scanning alerts on OpenClaw. Use when Codex needs to triage, redact, clean up, and resolve secret leakage found in issue comments, issue bodies, PR comments, or other GitHub content.
development
Maintainer workflow for OpenClaw releases, prereleases, changelog release notes, and publish validation. Use when Codex needs to prepare or verify stable or beta release steps, align version naming, assemble release notes, check release auth requirements, or validate publish-time commands and artifacts.
development
Run, watch, debug, and extend OpenClaw QA testing with qa-lab and qa-channel. Use when Codex needs to execute the repo-backed QA suite, inspect live QA artifacts, debug failing scenarios, add new QA scenarios, or explain the OpenClaw QA workflow. Prefer the live OpenAI lane with regular openai/gpt-5.4 in fast mode; do not use gpt-5.4-pro or gpt-5.4-mini unless the user explicitly overrides that policy.
development
End-to-end Parallels smoke, upgrade, and rerun workflow for OpenClaw across macOS, Windows, and Linux guests. Use when Codex needs to run, rerun, debug, or interpret VM-based install, onboarding, gateway smoke tests, latest-release-to-main upgrade checks, fresh snapshot retests, or optional Discord roundtrip verification under Parallels.