More conveniences
Pre-release
Pre-release
·
30 commits
to master
since this release
Examples below shows how to use new conveniences with demo User
table
/// without connection, useful if you have only one query there
func databaseRequest(on req: Request) -> EventLoopFuture<SomeResult> {
User.query(on: .psqlEnvironment, on: req)
// optionally use `where` clause with all SwifQL's power
.where(\User.$email == "john@gmail.com")
/// also available
// .join(...)
// .groupBy(...)
// .having(...)
// .orderBy(...)
// .offset(...)
// .limit(...)
/// and select one of methods listed below to get the result
.first() // to get `EventLoopFuture<User?>`
.all() // to get `EventLoopFuture<[User]>`
.count() // to get EventLoopFuture<Int64>
.delete() // to execute DELETE FROM "User" query, returns Void
}
/// with connection
func databaseRequest(on req: Request) -> EventLoopFuture<[User]> {
req.postgres.connection(to: .psqlEnvironment) { conn in
// you could build query the same way as shown in above example
User.query(on: conn).all()
}
}
💡 available for all dialects