hummingbird-project/hummingbird-fluent
Hummingbird interface to the [Fluent](https://github.com/vapor/fluent-kit) database ORM.
Usage
The following initializes an SQLite database and adds a single migration CreateTodo.
import FluentSQLiteDriver
import HummingbirdFluent
let logger = Logger(label: "MyApp")
let fluent = Fluent(logger: logger)
// add sqlite database
fluent.databases.use(.sqlite(.file("db.sqlite")), as: .sqlite)
// add migration
await fluent.migrations.add(CreateTodo())
// migrate
if arguments.migrate {
try fluent.migrate().wait()
}Fluent can be used from a route as follows.
let router = Router()
router
.group("todos")
.get(":id") { request, context in
guard let id = context.parameters.get("id", as: UUID.self) else { return request.failure(HTTPError(.badRequest)) }
return Todo.find(id, on: fluent.db())
}Here we are returning a Todo with an id specified in the request URI.
You can then bring this together by creating an application that uses the router and adding fluent to its list of services
var app = Application(router: router)
// add the fluent service to the application so it can manage shutdown correctly
app.addServices(fluent)
try await app.runService()Documentation
Reference documentation for HummingbirdFluent can be found here here and you can find more documentation on Fluent here.
Package Metadata
Repository: hummingbird-project/hummingbird-fluent
Default branch: main
README: README.md