From cfd5abc1a7ce6f2d9a295ae44e4efe344be7553b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Thu, 10 Dec 2015 13:28:34 +0100 Subject: [PATCH] Documentation --- .../Core/Protocols/DatabaseTableMapping.swift | 2 +- README.md | 27 ++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/GRDB/Core/Protocols/DatabaseTableMapping.swift b/GRDB/Core/Protocols/DatabaseTableMapping.swift index a1a004904..4ec2e8b4d 100644 --- a/GRDB/Core/Protocols/DatabaseTableMapping.swift +++ b/GRDB/Core/Protocols/DatabaseTableMapping.swift @@ -9,7 +9,7 @@ /// /// DatabaseTableMapping is adopted by Record. public protocol DatabaseTableMapping { - /// The name of the database table. + /// The name of the database table static func databaseTableName() -> String } diff --git a/README.md b/README.md index 522da871a..8a2b34442 100644 --- a/README.md +++ b/README.md @@ -1496,11 +1496,36 @@ See also the [Record](#records) class, which builds on top of RowConvertible and ```swift public protocol DatabaseTableMapping { - /// The name of the database table. + /// The name of the database table static func databaseTableName() -> String } ``` +For example: + +```swift +// CREATE TABLE persons ( +// id INTEGER PRIMARY KEY, +// name TEXT, +// email TEXT UNIQUE COLLATE NOCASE +// ) +struct Person : RowConvertible, DatabaseTableMapping { + var id: Int64? + var name: String? + var email: String? + + static func databaseTableName() -> String { + return "persons" + } + + init(row: Row) { + id = row.value(named: "id") + name = row.value(named: "name") + email = row.value(named: "email") + } +} +``` + You are then granted with fetching methods based on database keys: ```swift