         }
         return dictionary
     }
+    
+    
+    // MARK: - CollectionType
+    
+    // TODO: test the row as collection
+    
+    // Use a custom index, so that we eventually can provide a subscript(Int)
+    // that returns a DatabaseValue.
+    public struct RowIndex: ForwardIndexType {
+        let index: Int
+        
+        init(_ index: Int) {
+            self.index = index
+        }
+        
+        public func successor() -> RowIndex {
+            return RowIndex(index+1)
+        }
+    }
+    
+    public func generate() -> IndexingGenerator<Row> {
+        return IndexingGenerator(self)
+    }
+    
+    public var startIndex: RowIndex {
+        return Index(0)
+    }
+    
+    public var endIndex: RowIndex {
+        return Index(impl.count)
+    }
+    
+    public subscript(index: RowIndex) -> (String, SQLiteValue) {
+        return (
+            self.impl.columnNameAtIndex(index.index),
+            self.impl.sqliteValueAtIndex(index.index))
+    }
+    
+    
+    // MARK: - DictionaryRowImpl
+    
+    private struct DictionaryRowImpl: RowImpl {
+        let sqliteDictionary: [String: SQLiteValue]
+        
+        var count: Int {
+            return sqliteDictionary.count
+        }
+        
+        init (sqliteDictionary: [String: SQLiteValue]) {
+            self.sqliteDictionary = sqliteDictionary
+        }
+        
+        func sqliteValueAtIndex(index: Int) -> SQLiteValue {
+            return sqliteDictionary[advance(sqliteDictionary.startIndex, index)].1
+        }
+        
+        func columnNameAtIndex(index: Int) -> String {
+            return sqliteDictionary[advance(sqliteDictionary.startIndex, index)].0
+        }
+        
+        func indexForColumnNamed(name: String) -> Int? {
+            if let index = sqliteDictionary.indexForKey(name) {
+                return distance(sqliteDictionary.startIndex, index)
+            } else {
+                return nil
+            }
+        }
+    }
+    
+    
+    // MARK: - SafeRowImpl
     
     // SafeRowImpl can be safely accessed after sqlite3_step() and sqlite3_finalize() has been called.
     // It preserves the column ordering of the statement.

            return dic
        }
    }
    
    private struct DictionaryRowImpl: RowImpl {
        let sqliteDictionary: [String: SQLiteValue]
        
        init (sqliteDictionary: [String: SQLiteValue]) {
            self.sqliteDictionary = sqliteDictionary
        }
        
        func sqliteValueAtIndex(index: Int) -> SQLiteValue {
            return sqliteDictionary[advance(sqliteDictionary.startIndex, index)].1
        }
        
        func indexForColumnNamed(name: String) -> Int? {
            if let index = sqliteDictionary.indexForKey(name) {
                return distance(sqliteDictionary.startIndex, index)
            } else {
                return nil
            }
        }
    }
}

        self.impl = DictionaryRowImpl(sqliteDictionary: sqliteDictionary)
    }
    
    
    // MARK: - Values
    
    public func hasColumn(name: String) -> Bool {
        return impl.sqliteDictionary.indexForKey(name) != nil
    }
