Documentation

This commit is contained in:
Gwendal Roué committed 2015-12-10 13:28:34 +01:00
1 parent 03d7d494fa
commit cfd5abc1a7
2 files changed
+27 -2

No files matched your search

@@ -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
}
+26 -1
View File
@@ -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