Giter Site home page Giter Site logo

zunda-pixel / hummingbird-fluent Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hummingbird-project/hummingbird-fluent

0.0 0.0 0.0 89 KB

Hummingbird integration with Fluent database ORM

License: Apache License 2.0

Shell 12.07% Swift 86.68% Dockerfile 1.25%

hummingbird-fluent's Introduction

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.