Swiftpack.co - hummingbird-project/hummingbird-fluent as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by hummingbird-project.
hummingbird-project/hummingbird-fluent 1.0.0-alpha.2
Hummingbird integration with Fluent database ORM
⭐️ 4
🕓 2 days ago
iOS macOS tvOS
.package(url: "https://github.com/hummingbird-project/hummingbird-fluent.git", from: "1.0.0-alpha.2")

Hummingbird Fluent

Hummingbird interface to the Fluent database ORM.

Hummingbird doesn't come with any database drivers or ORM. This library provides a connection to Vapor's database ORM. The Vapor guys have been generous and forward thinking enough to ensure Fluent-kit can be used independent of Vapor. They have a small library that links Vapor to Fluent, this library does pretty much the same thing for Hummingbird.


The following initializes an SQLite database and adds a single migration CreateTodo.

import FluentSQLiteDriver
import HummingbirdFluent

let app = HBApplication()
// add Fluent
// add sqlite database
app.fluent.databases.use(.sqlite(.file("db.sqlite")), as: .sqlite)
// add migrations
// migrate
if arguments.migrate {
    try app.fluent.migrate().wait()

In general the interface to Fluent follows the same pattern as Vapor, except the db and migrations objects are only accessible from within the fluent object, and you need to call HBApplication.addFluent() at initialization.

Fluent can be used from a route as follows. The database is accessible via HBRequest.db.

    .get(":id") { request in 
        guard let id = request.parameters.get("id", as: UUID.self) else { return request.failure(HBHTTPError(.badRequest)) }
        return Todo.find(id, on: request.db)

Here we are returning a Todo with an id specified in the path.

You can find more documentation on Fluent here.


Stars: 4
Last commit: 2 days ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

v1.0.0 Alpha 2
2 days ago

Minor release changes

  • Requires Swift 5.5 (inline with SwiftNIO)

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics