Releases: vapor/fluent-kit
Pagination and Range
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
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
Adds a test to ensure models with UInt8
-backed enum properties work properly.
Don't eager load on empty result set
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
FluentKit 1.0.0 Beta 2.4
- Fix array test to store json array as
.array(of: .json)
(#111)
FluentKit 1.0.0 Beta 2.3
FluentKit 1.0.0 Beta 2.2
FluentKit 1.0.0 Beta 2.1
- Fixes an operator precedence issue when querying on soft-deletable models. (#104)
FluentKit 1.0.0 Beta 2
- 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)