GRDB.swift v0.74.0 Release Notes
-
๐ Released July 6, 2016
๐ New
๐ TableMapping protocol lets you delete rows identified by their primary keys, or any columns involved in a unique index (closes #56, documentation):
try Person.deleteOne(db, key: 1) try Person.deleteOne(db, key: ["email": "[email protected]"]) try Citizenship.deleteOne(db, key: ["personID": 1, "countryCode": "FR"]) try Country.deleteAll(db, keys: ["FR", "US"])
๐ฅ Breaking change
The
fetch(_:keys:)
,fetchAll(_:keys:)
andfetchOne(_:key:)
methods used to accept any dictionary of column/value pairs to identify rows. Now these methods raise a fatal error if the columns are not guaranteed, at the database level, to uniquely identify rows: columns must be the primary key, or involved in a unique index:// CREATE TABLE persons ( // id INTEGER PRIMARY KEY, -- can fetch and delete by id // email TEXT UNIQUE, -- can fetch and delete by email // name TEXT -- nope // ) Person.fetchOne(db, key: ["id": 1]) // Person? Person.fetchOne(db, key: ["email": "[email protected]"]) // Person? Person.fetchOne(db, key: ["name": "Arthur"]) // fatal error: table persons has no unique index on column name.
This change harmonizes the behavior of those fetching methods with the new
deleteOne(_:key:)
anddeleteAll(_:keys:)
.