From 4eecc9af20f44a96b65cdf516cce6e77cff14469 Mon Sep 17 00:00:00 2001 From: Christoph Hagen Date: Tue, 11 Oct 2022 11:51:52 +0200 Subject: [PATCH] Improve user field declarations --- Sources/App/Model/User.swift | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/Sources/App/Model/User.swift b/Sources/App/Model/User.swift index f2bca41..7520b80 100644 --- a/Sources/App/Model/User.swift +++ b/Sources/App/Model/User.swift @@ -1,7 +1,18 @@ import FluentSQLiteDriver +import FluentSQL 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 final class User: Model { @@ -26,19 +37,19 @@ final class User: Model { var id: UUID? /// The user's full name. - @Field(key: Key.name.key) + @Field(.name) var name: String /// The hash of the user's password - @Field(key: Key.hash.key) + @Field(.hash) var passwordHash: String /// The user's total points - @Field(key: Key.points.key) + @Field(.points) var points: Int - // Example of an optional parent relation. - @OptionalParent(key: Key.table.key) + /// The table to which this user currently belongs + @OptionalParent(.table) var table: Table? init() { }