mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-25 04:07:47 +00:00
Drop deprecated TableMapping.primaryKeyRowComparator(_:)
This commit is contained in:
1 parent
e36219e408
commit
4ec3e0f7d8
3 files changed
-130
No files matched your search
@@ -360,14 +360,6 @@
|
||||
564F9C321F07611700877A00 /* DatabaseFunction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564F9C2C1F075DD200877A00 /* DatabaseFunction.swift */; };
|
||||
564F9C331F07611800877A00 /* DatabaseFunction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564F9C2C1F075DD200877A00 /* DatabaseFunction.swift */; };
|
||||
564F9C341F07611900877A00 /* DatabaseFunction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564F9C2C1F075DD200877A00 /* DatabaseFunction.swift */; };
|
||||
565029C81E914DB700615A2C /* TableMappingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565029C71E914DB700615A2C /* TableMappingTests.swift */; };
|
||||
565029C91E914DB700615A2C /* TableMappingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565029C71E914DB700615A2C /* TableMappingTests.swift */; };
|
||||
565029CA1E914DB700615A2C /* TableMappingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565029C71E914DB700615A2C /* TableMappingTests.swift */; };
|
||||
565029CB1E914DB700615A2C /* TableMappingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565029C71E914DB700615A2C /* TableMappingTests.swift */; };
|
||||
565029CC1E914DB700615A2C /* TableMappingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565029C71E914DB700615A2C /* TableMappingTests.swift */; };
|
||||
565029CD1E914DB700615A2C /* TableMappingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565029C71E914DB700615A2C /* TableMappingTests.swift */; };
|
||||
565029CE1E914DB700615A2C /* TableMappingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565029C71E914DB700615A2C /* TableMappingTests.swift */; };
|
||||
565029CF1E914DB700615A2C /* TableMappingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565029C71E914DB700615A2C /* TableMappingTests.swift */; };
|
||||
565490B41D5A4820005622CB /* GRDB.h in Headers */ = {isa = PBXBuildFile; fileRef = DC3773F819C8CBB3004FCF85 /* GRDB.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
565490B51D5A4827005622CB /* GRDB-Bridging.h in Headers */ = {isa = PBXBuildFile; fileRef = DC2393C61ABE35F8003FF113 /* GRDB-Bridging.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
565490B61D5AE236005622CB /* Configuration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238701B9C75030082EB20 /* Configuration.swift */; };
|
||||
@@ -2005,7 +1997,6 @@
|
||||
564A50C61BFF4B7F00B3A3A2 /* DatabaseCollationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseCollationTests.swift; sourceTree = "<group>"; };
|
||||
564F9C1D1F069B4E00877A00 /* DatabaseAggregateTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseAggregateTests.swift; sourceTree = "<group>"; };
|
||||
564F9C2C1F075DD200877A00 /* DatabaseFunction.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseFunction.swift; sourceTree = "<group>"; };
|
||||
565029C71E914DB700615A2C /* TableMappingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableMappingTests.swift; sourceTree = "<group>"; };
|
||||
565490A01D5A4798005622CB /* GRDB.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = GRDB.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
565490E51D5AE282005622CB /* libsqlite3.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libsqlite3.tbd; path = Platforms/WatchOS.platform/Developer/SDKs/WatchOS2.2.sdk/usr/lib/libsqlite3.tbd; sourceTree = DEVELOPER_DIR; };
|
||||
56553C181C3E906C00522B5C /* GRDBOSXCrashTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = GRDBOSXCrashTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
@@ -2536,7 +2527,6 @@
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
56FF453F1D2C23BA00F21EF9 /* TableMappingDeleteByKeyTests.swift */,
|
||||
565029C71E914DB700615A2C /* TableMappingTests.swift */,
|
||||
);
|
||||
name = TableMapping;
|
||||
sourceTree = "<group>";
|
||||
@@ -4109,7 +4099,6 @@
|
||||
5657AB471D108BA9006283EF /* FoundationNSNullTests.swift in Sources */,
|
||||
560FC5811CB00B880014AA8E /* RecordCopyTests.swift in Sources */,
|
||||
560FC5821CB00B880014AA8E /* RawRepresentable+DatabaseValueConvertibleTests.swift in Sources */,
|
||||
565029C91E914DB700615A2C /* TableMappingTests.swift in Sources */,
|
||||
567E55ED1D2BDD3D00CC6F79 /* EncryptionTests.swift in Sources */,
|
||||
56741EA91E66A8B3003E422D /* RequestTests.swift in Sources */,
|
||||
56176C641EACCCC7000F3F2B /* FTS5WrapperTokenizerTests.swift in Sources */,
|
||||
@@ -4357,7 +4346,6 @@
|
||||
567156411CB16729007DC145 /* PersistableTests.swift in Sources */,
|
||||
5657AB501D108BA9006283EF /* FoundationNSNumberTests.swift in Sources */,
|
||||
567156441CB16729007DC145 /* RecordSubClassTests.swift in Sources */,
|
||||
565029CA1E914DB700615A2C /* TableMappingTests.swift in Sources */,
|
||||
5690C3391D23E7D200E59934 /* FoundationDateTests.swift in Sources */,
|
||||
56741EAA1E66A8B3003E422D /* RequestTests.swift in Sources */,
|
||||
56176C6A1EACCCC8000F3F2B /* FTS5WrapperTokenizerTests.swift in Sources */,
|
||||
@@ -4585,7 +4573,6 @@
|
||||
56AFCA551CB1AA9900F48B96 /* RawRepresentable+DatabaseValueConvertibleTests.swift in Sources */,
|
||||
5698ACBB1DA6285E0056AF8C /* FTS3TokenizerTests.swift in Sources */,
|
||||
56AFCA561CB1AA9900F48B96 /* DatabasePoolConcurrencyTests.swift in Sources */,
|
||||
565029CD1E914DB700615A2C /* TableMappingTests.swift in Sources */,
|
||||
56AFCA571CB1AA9900F48B96 /* TransactionObserverTests.swift in Sources */,
|
||||
56741EAD1E66A8B3003E422D /* RequestTests.swift in Sources */,
|
||||
56176C761EACCCCA000F3F2B /* FTS5WrapperTokenizerTests.swift in Sources */,
|
||||
@@ -4722,7 +4709,6 @@
|
||||
56AFCAAC1CB1ABC800F48B96 /* DatabaseValueConversionTests.swift in Sources */,
|
||||
5698ACBC1DA6285E0056AF8C /* FTS3TokenizerTests.swift in Sources */,
|
||||
5657AB441D108BA9006283EF /* FoundationNSDataTests.swift in Sources */,
|
||||
565029CE1E914DB700615A2C /* TableMappingTests.swift in Sources */,
|
||||
5623935D1DEE013C00A6B01F /* FilterCursorTests.swift in Sources */,
|
||||
56741EAE1E66A8B3003E422D /* RequestTests.swift in Sources */,
|
||||
56176C7C1EACCCCB000F3F2B /* FTS5WrapperTokenizerTests.swift in Sources */,
|
||||
@@ -4952,7 +4938,6 @@
|
||||
5607EFD41BB827FD00605DE3 /* TransactionObserverTests.swift in Sources */,
|
||||
5690C33B1D23E7D200E59934 /* FoundationDateTests.swift in Sources */,
|
||||
565D5D721BBC694D00DC9BD4 /* Row+FoundationTests.swift in Sources */,
|
||||
565029CC1E914DB700615A2C /* TableMappingTests.swift in Sources */,
|
||||
5623936D1DEE0CD200A6B01F /* FlattenCursorTests.swift in Sources */,
|
||||
567A80571D41350C00C7DCEC /* IndexInfoTests.swift in Sources */,
|
||||
5623935B1DEE013C00A6B01F /* FilterCursorTests.swift in Sources */,
|
||||
@@ -5089,7 +5074,6 @@
|
||||
56D496C41D813767008276D7 /* DatabaseQueueTests.swift in Sources */,
|
||||
56D496851D813147008276D7 /* StatementArgumentsTests.swift in Sources */,
|
||||
56D496B81D813465008276D7 /* DataMemoryTests.swift in Sources */,
|
||||
565029C81E914DB700615A2C /* TableMappingTests.swift in Sources */,
|
||||
56D496541D812F5B008276D7 /* SQLExpressionLiteralTests.swift in Sources */,
|
||||
56D496961D81317B008276D7 /* PersistableTests.swift in Sources */,
|
||||
5698AC9E1DA4B0430056AF8C /* FTS4TableBuilderTests.swift in Sources */,
|
||||
@@ -5413,7 +5397,6 @@
|
||||
5690C33E1D23E7D200E59934 /* FoundationDateTests.swift in Sources */,
|
||||
567A805A1D41350C00C7DCEC /* IndexInfoTests.swift in Sources */,
|
||||
5674A7291F30A9090095F066 /* RowConvertibleDecodableTests.swift in Sources */,
|
||||
565029CF1E914DB700615A2C /* TableMappingTests.swift in Sources */,
|
||||
F3BA81211CFB3063003DC1BA /* RecordPrimaryKeyNoneTests.swift in Sources */,
|
||||
F3BA80F71CFB3021003DC1BA /* SelectStatementTests.swift in Sources */,
|
||||
56F3E7501E66F83A00BF0F01 /* ResultCodeTests.swift in Sources */,
|
||||
@@ -5642,7 +5625,6 @@
|
||||
F3BA80FA1CFB3021003DC1BA /* SelectStatementTests.swift in Sources */,
|
||||
5674A7271F30A9090095F066 /* RowConvertibleDecodableTests.swift in Sources */,
|
||||
F3BA81191CFB305F003DC1BA /* QueryInterfaceRequestTests.swift in Sources */,
|
||||
565029CB1E914DB700615A2C /* TableMappingTests.swift in Sources */,
|
||||
F3BA812F1CFB3064003DC1BA /* RecordPrimaryKeyNoneTests.swift in Sources */,
|
||||
5690C33A1D23E7D200E59934 /* FoundationDateTests.swift in Sources */,
|
||||
56F3E74C1E66F83A00BF0F01 /* ResultCodeTests.swift in Sources */,
|
||||
|
||||
@@ -201,56 +201,3 @@ extension TableMapping {
|
||||
}
|
||||
}
|
||||
|
||||
extension TableMapping {
|
||||
/// Returns a function that returns the primary key of a row.
|
||||
///
|
||||
/// If the table has no primary key, and selectsRowID is true, the primary
|
||||
/// key is the "rowid" column.
|
||||
///
|
||||
/// try dbQueue.inDatabase { db in
|
||||
/// let primaryKey = try Person.rowPrimaryKey(db)
|
||||
/// let row = try Row.fetchOne(db, "SELECT * FROM persons")!
|
||||
/// primaryKey(row) // ["id": 1]
|
||||
/// }
|
||||
///
|
||||
/// - throws: A DatabaseError if table does not exist.
|
||||
static func rowPrimaryKey(_ db: Database) throws -> (Row) -> [String: DatabaseValue] {
|
||||
if let primaryKey = try db.primaryKey(databaseTableName) {
|
||||
let columns = primaryKey.columns
|
||||
return { row in Dictionary(uniqueKeysWithValues: columns.lazy.map { ($0, row[$0]) }) }
|
||||
} else if selectsRowID {
|
||||
return { row in [Column.rowID.name: row[.rowID]] }
|
||||
} else {
|
||||
return { _ in [:] }
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a function that returns true if and only if two rows have the
|
||||
/// same primary key and both primary keys contain at least one non-null
|
||||
/// value.
|
||||
///
|
||||
/// try dbQueue.inDatabase { db in
|
||||
/// let comparator = try Person.primaryKeyRowComparator(db)
|
||||
/// let row0 = Row(["id": nil, "name": "Unsaved"])
|
||||
/// let row1 = Row(["id": 1, "name": "Arthur"])
|
||||
/// let row2 = Row(["id": 1, "name": "Arthur"])
|
||||
/// let row3 = Row(["id": 2, "name": "Barbara"])
|
||||
/// comparator(row0, row0) // false
|
||||
/// comparator(row1, row2) // true
|
||||
/// comparator(row1, row3) // false
|
||||
/// }
|
||||
///
|
||||
/// - throws: A DatabaseError if table does not exist.
|
||||
/// - attention: This method is deprecated. It will be removed is the next
|
||||
/// major version of the library, without any replacement.
|
||||
@available(*, deprecated)
|
||||
public static func primaryKeyRowComparator(_ db: Database) throws -> (Row, Row) -> Bool {
|
||||
let primaryKey = try rowPrimaryKey(db)
|
||||
return { (lhs, rhs) in
|
||||
let (lhs, rhs) = (primaryKey(lhs), primaryKey(rhs))
|
||||
guard lhs.contains(where: { !$1.isNull }) else { return false }
|
||||
guard rhs.contains(where: { !$1.isNull }) else { return false }
|
||||
return lhs == rhs
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
import XCTest
|
||||
#if GRDBCIPHER
|
||||
import GRDBCipher
|
||||
#elseif GRDBCUSTOMSQLITE
|
||||
import GRDBCustomSQLite
|
||||
#else
|
||||
import GRDB
|
||||
#endif
|
||||
|
||||
class TableMappingTests: GRDBTestCase {
|
||||
|
||||
// Test deprecated method primaryKeyRowComparator
|
||||
func testPrimaryKeyRowComparatorWithIntegerPrimaryKey() throws {
|
||||
struct Person : TableMapping {
|
||||
static let databaseTableName = "persons"
|
||||
}
|
||||
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.create(table: "persons") { t in
|
||||
t.column("id", .integer).primaryKey()
|
||||
t.column("name", .text)
|
||||
}
|
||||
|
||||
let comparator = try Person.primaryKeyRowComparator(db)
|
||||
let row0: Row = ["id": nil, "name": "Unsaved"]
|
||||
let row1: Row = ["id": 1, "name": "Arthur"]
|
||||
let row2: Row = ["id": 1, "name": "Arthur"]
|
||||
let row3: Row = ["id": 2, "name": "Barbara"]
|
||||
XCTAssertFalse(comparator(row0, row0))
|
||||
XCTAssertTrue(comparator(row1, row2))
|
||||
XCTAssertFalse(comparator(row1, row3))
|
||||
}
|
||||
}
|
||||
|
||||
// Test deprecated method primaryKeyRowComparator
|
||||
func testPrimaryKeyRowComparatorWithHiddenRowIDPrimaryKey() throws {
|
||||
struct Person : TableMapping {
|
||||
static let databaseTableName = "persons"
|
||||
static let selectsRowID = true
|
||||
}
|
||||
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.create(table: "persons") { t in
|
||||
t.column("name", .text)
|
||||
}
|
||||
|
||||
let comparator = try Person.primaryKeyRowComparator(db)
|
||||
let row0: Row = ["rowid": nil, "name": "Unsaved"]
|
||||
let row1: Row = ["rowid": 1, "name": "Arthur"]
|
||||
let row2: Row = ["rowid": 1, "name": "Arthur"]
|
||||
let row3: Row = ["rowid": 2, "name": "Barbara"]
|
||||
XCTAssertFalse(comparator(row0, row0))
|
||||
XCTAssertTrue(comparator(row1, row2))
|
||||
XCTAssertFalse(comparator(row1, row3))
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user