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.1.0
Hummingbird integration with Fluent database ORM
⭐️ 6
🕓 15 weeks ago
iOS macOS tvOS
.package(url: "https://github.com/hummingbird-project/hummingbird-fluent.git", from: "1.1.0")

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: 6
Last commit: 15 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

15 weeks ago

Minor release changes

  • Setup HBFluent and HBFluentPersistDriver so they can be used separate from HBApplication

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