Schafkopf-Server/Sources/App/Model/Table.swift

53 lines
1.1 KiB
Swift
Raw Normal View History

2021-12-22 22:11:37 +01:00
import FluentSQLiteDriver
import Vapor
/// A registered user
class Table: Model {
enum Key: String {
case id = "id"
case name = "name"
case isPublic = "public"
case language = "language"
var key: FieldKey {
.init(stringLiteral: rawValue)
}
}
/// The name of the SQLite table
static let schema = "table"
/// The unique identifier for this table.
@ID(key: .id)
var id: UUID?
/// The user's full name.
@Field(key: Key.name.key)
var name: String
/// The players sitting at the table
@Children(for: \.$table)
var players: [User]
@Field(key: Key.isPublic.key)
var isPublic: Bool
@Enum(key: Key.language.key)
var language: SupportedLanguage
required init() { }
/// Creates a new table.
init(id: UUID? = nil, name: String, isPublic: Bool = true, language: SupportedLanguage = .english) {
self.id = id
self.name = name
self.isPublic = isPublic
self.language = language
}
var stringId: String {
"\(id!)"
}
}