mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-25 04:07:47 +00:00
Documentation
This commit is contained in:
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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user