Code Monkey home page Code Monkey logo

Comments (2)

martinlasek avatar martinlasek commented on June 9, 2024

@DanielLiuCD
I am not sure if you're trying to use FluentKit directly or if you're looking to use Fluent.
In the latter case there's docs here: https://docs.vapor.codes/fluent/overview/ 🙂

from fluent-kit.

0xTim avatar 0xTim commented on June 9, 2024

To use FluentKit without Fluent or Vapor you'll need something like

/// Encapsulates the state maintained by clients of FluentKit.
public final class FluentKitContext {
    public let threadPool: NIOThreadPool
    public let eventLoopGroup: EventLoopGroup
    public let logger: Logger
    public let databases: Databases
    public let migrations: Migrations

    public init(eventLoopGroup: EventLoopGroup, logger: Logger = .init(label: "Fluent")) {
        self.threadPool = .init(numberOfThreads: 1)
        self.eventLoopGroup = eventLoopGroup
        self.logger = logger
        self.databases = .init(threadPool: threadPool, on: eventLoopGroup)
        self.migrations = .init()
    }

    deinit {
        self.databases.shutdown()
        try! self.threadPool.syncShutdownGracefully()
    }

    public func use(database factory: DatabaseConfigurationFactory, as id: DatabaseID, isDefault: Bool? = nil) {
        self.databases.use(factory, as: id, isDefault: isDefault)
    }

    public func use(database driver: DatabaseConfiguration, as id: DatabaseID, isDefault: Bool? = nil) {
        self.databases.use(driver, as: id, isDefault: isDefault)
    }

    public func add(migration: Migration, to id: DatabaseID? = nil) {
        self.migrations.add(migration, to: id)
    }

    public func migrate() -> EventLoopFuture<Void> {
        let migrator = Migrator(databases: self.databases, migrations: self.migrations, logger: self.logger, on: self.eventLoopGroup.any())

        return migrator.setupIfNeeded().flatMap { migrator.prepareBatch() }
    }

    public func revert() -> EventLoopFuture<Void> {
        let migrator = Migrator(databases: self.databases, migrations: self.migrations, logger: self.logger, on: self.eventLoopGroup.any())

        return migrator.setupIfNeeded().flatMap { migrator.revertAllBatches() }
    }
}

from fluent-kit.

Related Issues (20)

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.