Releases: vapor/fluent-kit
SQLKit Updates
Adds support for SQLAlterTable.dropColumns
.
Fix ID.Generator.random Overwrite
ID.Generator.random
no longer overwrites user-supplied identifiers. Fixes #132.
@ID(key: "id", generatedBy: .random)
var id: UUID?
.random
is the default for UUID
.
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)