README.md

This commit is contained in:
Gwendal Roué committed 2016-03-25 21:07:17 +01:00
1 parent 03f89c9131
commit 310704e0c5
1 file changed
+8 -12
+8 -12
View File
@@ -730,7 +730,7 @@ if let date: NSDate? = dbv.failableValue() {
#### Rows as Dictionaries
**Rows can be seen as dictionaries** of [DatabaseValue](#databasevalue):
Row adopts the standard [CollectionType](https://developer.apple.com/library/ios/documentation/Swift/Reference/Swift_CollectionType_Protocol/index.html) protocol, and can be seen as a dictionary:
```swift
// Test if the column `date` is present:
@@ -738,16 +738,19 @@ if let databaseValue = row["date"] {
...
}
// the number of columns
row.count
// All the (columnName, databaseValue) tuples, from left to right:
for (columnName, databaseValue) in row {
...
}
```
Still, rows may contain duplicate keys:
**You can build rows from dictionaries** (standard Swift dictionaries and NSDictionary). See [Values](#values) for more information on supported types:
```swift
let row = Row(["name": "foo", "date": nil])
```
Yet rows are not real dictionaries, because they may contain duplicate keys:
```swift
let row = Row.fetchOne(db, "SELECT 1 AS foo, 2 AS foo")!
@@ -758,13 +761,6 @@ for (columnName, databaseValue) in row { ... } // ("foo", 1), ("foo", 2)
```
**You can build rows from dictionaries** (standard Swift dictionaries and NSDictionary). See [Values](#values) for more information on supported types:
```swift
let row = Row(["name": "foo", "date": nil])
```
### Value Queries
Instead of rows, you can directly fetch **[values](#values)**. Like rows, fetch them as **sequences**, **arrays**, or **single** values (see [fetching methods](#fetching-methods)). Values are extracted from the leftmost column of the SQL queries: