Skip to content

Releases: vapor/fluent-kit

Pagination and Range

16 Jan 22:50
7dc374e
Compare
Choose a tag to compare
Pagination and Range Pre-release
Pre-release

Adds paginate method to QueryBuilder which returns a Page of models. Page includes the array of models and a PageMetadata struct including information on current page, items per page, and total number of items.

Fluent adds a paginate(for:Request) method that automatically decodes the PageRequest from the Request's query string.

struct TodoController {
    func index(req: Request) throws -> EventLoopFuture<Page<Todo>> {
        Todo.query(on: req.db).paginate(for: req)
    }
}

Page can also map its items to different types.

let todos = Todo.query(on: req.db).paginate(for: req).map { page in
    page.map(Todo.Public.init)
}
print(todos) // ELFuture<Page<Todo.Public>>

In addition to pagination, QueryBuilder now supports range methods accepting Swift's Range literals.

query.range(2..<5) // returns at most 3 results, offset by 2
query.range(..<5) // returns at most 5 results

Added Model.hasChanges Property

16 Jan 18:05
d3bb891
Compare
Choose a tag to compare
Pre-release

Adds a .hasChanges computed property to the Model protocol, which can be used to check if there are any fields that have had their values set, but the model has not yet been saved to the database.

Add UInt8-backed enum test

26 Dec 17:13
877bf49
Compare
Choose a tag to compare
Pre-release

Adds a test to ensure models with UInt8-backed enum properties work properly.

Don't eager load on empty result set

26 Dec 16:33
27d8b35
Compare
Choose a tag to compare
Pre-release

Fluent's QueryBuilder no longer attempts to run eager loads if all() returns zero models. This fixes an issue where attempting to eager load children on a query that returned zero models would result in a syntax error (#117).

Duplicate constraint name fix

17 Dec 04:42
c232981
Compare
Choose a tag to compare
Pre-release
  • Constraint names (unique and foreign key) now include the table name (#112, #113)

  • Publicized Model.key(for:) method for getting field key strings statically (#113)

FluentKit 1.0.0 Beta 2.4

13 Dec 23:51
5a2fbd6
Compare
Choose a tag to compare
Pre-release
  • Fix array test to store json array as .array(of: .json) (#111)

FluentKit 1.0.0 Beta 2.3

11 Dec 04:02
2535037
Compare
Choose a tag to compare
Pre-release
  • Standardized eagerLoaded value on all relations. (#106, #109)

FluentKit 1.0.0 Beta 2.2

11 Dec 01:27
e77647e
Compare
Choose a tag to compare
Pre-release
  • Adds array(of:) case to DatabaseSchema.DataType (#105)
  • Adds test for model containing array fields (#105)
  • Adds a performance test to FluentBenchmarker (#105)

FluentKit 1.0.0 Beta 2.1

10 Dec 22:46
Compare
Choose a tag to compare
Pre-release
  • Fixes an operator precedence issue when querying on soft-deletable models. (#104)

FluentKit 1.0.0 Beta 2

09 Dec 18:50
5df66ee
Compare
Choose a tag to compare
Pre-release
  • 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)