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

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. This package collates the fluent features into one. It also provides a driver for the Hummingbird Persist framework.

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.

GitHub

link
Stars: 6
Last commit: 5 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

v2.0.0 Beta 1
6 weeks ago

This is the first beta release of Hummingbird v2. Below is a list of the changes since the last alpha

Major release changes

  • The "HB" prefix on symbols has been removed. To help transition from previous symbols with the "HB" prefix we have added deprecated typealiases for the old symbols. eg typealias HBFluent = Fluent.
  • Migrations are now wrapped in FluentMigrations actor, instead of attaching them to the @MainActor.

Other changes

  • 2.0 code has now been merged into main branch.

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