Improve user field declarations

This commit is contained in:
Christoph Hagen 2022-10-11 11:51:52 +02:00
parent fc4afb70b1
commit 4eecc9af20

View File

@ -1,7 +1,18 @@
import FluentSQLiteDriver import FluentSQLiteDriver
import FluentSQL
import Vapor import Vapor
private extension FieldProperty {
convenience init(_ key: User.Key) {
self.init(key: key.key)
}
}
private extension OptionalParentProperty {
convenience init(_ key: User.Key) {
self.init(key: key.key)
}
}
/// A registered user /// A registered user
final class User: Model { final class User: Model {
@ -26,19 +37,19 @@ final class User: Model {
var id: UUID? var id: UUID?
/// The user's full name. /// The user's full name.
@Field(key: Key.name.key) @Field(.name)
var name: String var name: String
/// The hash of the user's password /// The hash of the user's password
@Field(key: Key.hash.key) @Field(.hash)
var passwordHash: String var passwordHash: String
/// The user's total points /// The user's total points
@Field(key: Key.points.key) @Field(.points)
var points: Int var points: Int
// Example of an optional parent relation. /// The table to which this user currently belongs
@OptionalParent(key: Key.table.key) @OptionalParent(.table)
var table: Table? var table: Table?
init() { } init() { }