Skip to content

FluentKit 1.0.0 Beta 2

Pre-release
Pre-release
Compare
Choose a tag to compare
@tanner0101 tanner0101 released this 09 Dec 18:50
5df66ee
  • Replaced Model lifecycle hooks with ModelMiddleware (#93)

The use of a middleware pattern for interacting with model lifecycle allows for greater control and flexibility. This also solves the longstanding issue of accessing shared state inside of lifecycle events. Now share state can be stored on the model middleware during app configuration.

Middleware also have the ability to change an event as it is passed through the middleware chain. For example, a middleware can intercept an update event and change it to a delete.

Multiple middleware can be configured to a single database. Additionally, AnyModelMiddleware can be used to create middleware for all Fluent models passing through a given DB.

Example:

// beta.1
final class User: Model {
    ...

    func didCreate(on db: Database) -> EventLoopFuture<Void> {
        print("user created")
    }
}

// beta.2
struct UserMiddleware: ModelMiddleware {
    func create(model: User, on db: Database, next: AnyModelResponder) -> EventLoopFuture<Void> {
        return next.create(model, on: db).map {
            print("user created")
        }
    }
}
  • Added foreign key support. (#83)

  • Publicized settable ID.exists for marking a model as already existing in the DB without fetching. (#94)

  • Fixed an issue when two children pointed to the same parent model. (#95)

  • Fixed an issue when create on an empty array of models (#97)

  • Enabled test discovery on Linux (#102)