mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-25 04:07:47 +00:00
Rename Row(dictionary:) to Row(_:)
This commit is contained in:
1 parent
84e7b6b3a9
commit
cf1b2fbc2e
10 files changed
+24
-24
No files matched your search
@@ -9,6 +9,7 @@ Release Notes
|
||||
|
||||
**Breaking Changes**
|
||||
|
||||
- `Row(dictionary:)` has been renamed `Row(_:)`.
|
||||
- `RowConvertible.awakeFromFetch()` now takes a database argument.
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import GRDB
|
||||
class DictionaryRowTests: GRDBTestCase {
|
||||
|
||||
func testRowAsSequence() {
|
||||
let row = Row(dictionary: ["a": 0, "b": 1, "c": 2])
|
||||
let row = Row(["a": 0, "b": 1, "c": 2])
|
||||
|
||||
var columnNames = Set<String>()
|
||||
var ints = Set<Int>()
|
||||
@@ -22,7 +22,7 @@ class DictionaryRowTests: GRDBTestCase {
|
||||
|
||||
func testRowValueAtIndex() {
|
||||
let dictionary: [String: DatabaseValueConvertible?] = ["a": 0, "b": 1, "c": 2]
|
||||
let row = Row(dictionary: dictionary)
|
||||
let row = Row(dictionary)
|
||||
|
||||
let aIndex = dictionary.startIndex.distanceTo(dictionary.indexForKey("a")!)
|
||||
let bIndex = dictionary.startIndex.distanceTo(dictionary.indexForKey("b")!)
|
||||
@@ -65,7 +65,7 @@ class DictionaryRowTests: GRDBTestCase {
|
||||
}
|
||||
|
||||
func testRowValueNamed() {
|
||||
let row = Row(dictionary: ["a": 0, "b": 1, "c": 2])
|
||||
let row = Row(["a": 0, "b": 1, "c": 2])
|
||||
|
||||
// Int extraction, form 1
|
||||
XCTAssertEqual(row.value(named: "a") as Int, 0)
|
||||
@@ -103,22 +103,22 @@ class DictionaryRowTests: GRDBTestCase {
|
||||
}
|
||||
|
||||
func testRowCount() {
|
||||
let row = Row(dictionary: ["a": 0, "b": 1, "c": 2])
|
||||
let row = Row(["a": 0, "b": 1, "c": 2])
|
||||
XCTAssertEqual(row.count, 3)
|
||||
}
|
||||
|
||||
func testRowColumnNames() {
|
||||
let row = Row(dictionary: ["a": 0, "b": 1, "c": 2])
|
||||
let row = Row(["a": 0, "b": 1, "c": 2])
|
||||
XCTAssertEqual(Array(row.columnNames).sort(), ["a", "b", "c"])
|
||||
}
|
||||
|
||||
func testRowDatabaseValues() {
|
||||
let row = Row(dictionary: ["a": 0, "b": 1, "c": 2])
|
||||
let row = Row(["a": 0, "b": 1, "c": 2])
|
||||
XCTAssertEqual(row.databaseValues.sort { ($0.value() as Int!) < ($1.value() as Int!) }, [0.databaseValue, 1.databaseValue, 2.databaseValue])
|
||||
}
|
||||
|
||||
func testRowSubscriptIsCaseInsensitive() {
|
||||
let row = Row(dictionary: ["name": "foo"])
|
||||
let row = Row(["name": "foo"])
|
||||
XCTAssertEqual(row["name"], "foo".databaseValue)
|
||||
XCTAssertEqual(row["NAME"], "foo".databaseValue)
|
||||
XCTAssertEqual(row["NaMe"], "foo".databaseValue)
|
||||
@@ -128,7 +128,7 @@ class DictionaryRowTests: GRDBTestCase {
|
||||
}
|
||||
|
||||
func testRowHasColumnIsCaseInsensitive() {
|
||||
let row = Row(dictionary: ["nAmE": "foo", "foo": 1])
|
||||
let row = Row(["nAmE": "foo", "foo": 1])
|
||||
XCTAssertTrue(row.hasColumn("name"))
|
||||
XCTAssertTrue(row.hasColumn("NAME"))
|
||||
XCTAssertTrue(row.hasColumn("Name"))
|
||||
|
||||
@@ -31,7 +31,7 @@ class RowConvertibleTests: GRDBTestCase {
|
||||
}
|
||||
|
||||
func testRowInitializer() {
|
||||
let row = Row(dictionary: ["firstName": "Arthur", "lastName": "Martin"])
|
||||
let row = Row(["firstName": "Arthur", "lastName": "Martin"])
|
||||
let s = SimpleRowConvertible.fromRow(row)
|
||||
XCTAssertEqual(s.firstName, "Arthur")
|
||||
XCTAssertEqual(s.lastName, "Martin")
|
||||
|
||||
@@ -5,13 +5,13 @@ class RowFoundationTests: GRDBTestCase {
|
||||
|
||||
func testRowFromInvalidNSDictionary() {
|
||||
let dictionary: NSDictionary = ["a": NSObject()]
|
||||
let row = Row(dictionary: dictionary)
|
||||
let row = Row(dictionary)
|
||||
XCTAssertTrue(row == nil)
|
||||
}
|
||||
|
||||
func testRowFromNSDictionary() {
|
||||
let dictionary: NSDictionary = ["a": "foo", "b": 1, "c": NSNull(), "d": NSDate(timeIntervalSince1970: 1443642439)]
|
||||
let row = Row(dictionary: dictionary)!
|
||||
let row = Row(dictionary)!
|
||||
|
||||
XCTAssertEqual(row.count, 4)
|
||||
XCTAssertEqual(row.value(named: "a") as String, "foo")
|
||||
@@ -21,7 +21,7 @@ class RowFoundationTests: GRDBTestCase {
|
||||
}
|
||||
|
||||
func testRowToNSDictionary() {
|
||||
let row = Row(dictionary: ["a": "foo", "b": 1, "c": nil, "d": NSDate(timeIntervalSince1970: 1443642439)])
|
||||
let row = Row(["a": "foo", "b": 1, "c": nil, "d": NSDate(timeIntervalSince1970: 1443642439)])
|
||||
let dictionary = row.toNSDictionary()
|
||||
XCTAssertEqual(dictionary.count, 4)
|
||||
XCTAssertTrue((dictionary["a"] as! NSString).isEqualToString("foo"))
|
||||
|
||||
@@ -44,7 +44,7 @@ class RecordEditedTests: GRDBTestCase {
|
||||
func testRecordIsEditedAfterInitFromRow() {
|
||||
// Create a Record from a row. The row may not come from the database.
|
||||
// So it is edited.
|
||||
let row = Row(dictionary: ["name": "Arthur", "age": 41])
|
||||
let row = Row(["name": "Arthur", "age": 41])
|
||||
let person = Person(row)
|
||||
XCTAssertTrue(person.hasPersistentChangedValues)
|
||||
}
|
||||
@@ -80,7 +80,7 @@ class RecordEditedTests: GRDBTestCase {
|
||||
|
||||
// Compare to an Int
|
||||
let record = IntegerPropertyOnRealAffinityColumn.fetchOne(db, "SELECT * FROM t")!
|
||||
let row2 = Row(dictionary: record.persistentDictionary)
|
||||
let row2 = Row(record.persistentDictionary)
|
||||
switch row2["value"]!.storage {
|
||||
case .Int64(let int64):
|
||||
XCTAssertEqual(int64, 1)
|
||||
@@ -268,7 +268,7 @@ class RecordEditedTests: GRDBTestCase {
|
||||
}
|
||||
|
||||
func testChangesAfterInitFromRow() {
|
||||
let person = Person(Row(dictionary:["name": "Arthur", "age": 41]))
|
||||
let person = Person(Row(["name": "Arthur", "age": 41]))
|
||||
let changes = person.persistentChangedValues
|
||||
XCTAssertEqual(changes.count, 4)
|
||||
for (column, old) in changes {
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ public final class Row: CollectionType {
|
||||
}
|
||||
|
||||
/// Builds a row from an dictionary of values.
|
||||
public init(dictionary: [String: DatabaseValueConvertible?]) {
|
||||
public init(_ dictionary: [String: DatabaseValueConvertible?]) {
|
||||
var databaseDictionary = [String: DatabaseValue]()
|
||||
for (key, value) in dictionary {
|
||||
databaseDictionary[key] = value?.databaseValue ?? .Null
|
||||
|
||||
@@ -10,7 +10,7 @@ extension Row {
|
||||
/// NSString, NSURL).
|
||||
///
|
||||
/// - parameter dictionary: An NSDictionary.
|
||||
public convenience init?(dictionary: NSDictionary) {
|
||||
public convenience init?(_ dictionary: NSDictionary) {
|
||||
var initDictionary = [String: DatabaseValueConvertible?]()
|
||||
for (key, value) in dictionary {
|
||||
guard let columnName = key as? String else {
|
||||
@@ -21,7 +21,7 @@ extension Row {
|
||||
}
|
||||
initDictionary[columnName] = databaseValue
|
||||
}
|
||||
self.init(dictionary: initDictionary)
|
||||
self.init(initDictionary)
|
||||
}
|
||||
|
||||
/// Converts a row to an NSDictionary.
|
||||
|
||||
@@ -110,7 +110,7 @@ public class Record : RowConvertible, DatabaseTableMapping, DatabasePersistable
|
||||
/// - returns: A copy of self.
|
||||
@warn_unused_result
|
||||
public func copy() -> Self {
|
||||
let copy = self.dynamicType.fromRow(Row(dictionary: persistentDictionary))
|
||||
let copy = self.dynamicType.fromRow(Row(persistentDictionary))
|
||||
copy.referenceRow = referenceRow
|
||||
return copy
|
||||
}
|
||||
@@ -141,7 +141,7 @@ public class Record : RowConvertible, DatabaseTableMapping, DatabasePersistable
|
||||
if newValue {
|
||||
referenceRow = nil
|
||||
} else {
|
||||
referenceRow = Row(dictionary: persistentDictionary)
|
||||
referenceRow = Row(persistentDictionary)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -492,10 +492,10 @@ for (columnName, databaseValue) in row { ... } // ("foo", 1), ("foo", 2)
|
||||
|
||||
Rows is a fundamental type in GRDB, used by many other APIs.
|
||||
|
||||
From time to time, you'll want to build a custom one from scratch. Use the dictionary initializer:
|
||||
From time to time, you'll want to build a custom one from scratch. Use the dictionary and NSDictionary initializers:
|
||||
|
||||
```swift
|
||||
Row(dictionary: ["name": "foo", "date": nil])
|
||||
Row(["name": "foo", "date": nil])
|
||||
```
|
||||
|
||||
See [Values](#values) for more information on supported types.
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
- [ ] Row dictionary initializer should be replaced with a initializer from sequences of (string, value) pairs (including dictionaries).
|
||||
- [ ] Unify Database.execute() and Database.executeMultiStatement()
|
||||
|
||||
Not sure:
|
||||
@@ -27,4 +26,4 @@ Reading list:
|
||||
- https://www.sqlite.org/undoredo.html
|
||||
- http://www.sqlite.org/intern-v-extern-blob.html
|
||||
- List of documentation keywords: https://swift.org/documentation/api-design-guidelines.html#special-instructions
|
||||
- https://www.zetetic.net/sqlcipher/
|
||||
- https://www.zetetic.net/sqlcipher/
|
||||
Reference in new issue
Block a user