Skip to content

Commit

Permalink
[BREAKING] DatabaseCollation is no longer Hashable
Browse files Browse the repository at this point in the history
  • Loading branch information
groue committed Aug 25, 2024
1 parent eedd165 commit c1f59df
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 21 deletions.
6 changes: 3 additions & 3 deletions GRDB/Core/Database.swift
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ public final class Database: CustomStringConvertible, CustomDebugStringConvertib
private var functions: [DatabaseFunction.ID: DatabaseFunction] = [:]

/// The registered custom SQL collations.
private var collations = Set<DatabaseCollation>()
private var collations: [DatabaseCollation.ID: DatabaseCollation] = [:]

/// Support for `beginReadOnly()` and `endReadOnly()`.
private var readOnlyDepth = 0
Expand Down Expand Up @@ -734,7 +734,7 @@ public final class Database: CustomStringConvertible, CustomDebugStringConvertib
/// let dbPool = try DatabasePool(path: ..., configuration: config)
/// ```
public func add(collation: DatabaseCollation) {
collations.update(with: collation)
collations[collation.id] = collation
let collationPointer = Unmanaged.passUnretained(collation).toOpaque()
let code = sqlite3_create_collation_v2(
sqliteConnection,
Expand All @@ -753,7 +753,7 @@ public final class Database: CustomStringConvertible, CustomDebugStringConvertib

/// Removes a collation.
public func remove(collation: DatabaseCollation) {
collations.remove(collation)
collations.removeValue(forKey: collation.id)
sqlite3_create_collation_v2(
sqliteConnection,
collation.name,
Expand Down
18 changes: 0 additions & 18 deletions GRDB/Core/DatabaseCollation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,3 @@ public final class DatabaseCollation: Identifiable, Sendable {
}
}
}

extension DatabaseCollation: Hashable {
// Collation equality is based on the sqlite3_strnicmp SQLite function.
// (see https://www.sqlite.org/c3ref/create_collation.html). Computing
// a hash value that honors the Swift Hashable contract (value equality
// implies hash equality) is thus non trivial. But it's not that
// important, since this hashValue is only used when one adds
// or removes a collation from a database connection.
public func hash(into hasher: inout Hasher) {
hasher.combine(0)
}

/// Two collations are equal if they share the same name (case insensitive)
public static func == (lhs: DatabaseCollation, rhs: DatabaseCollation) -> Bool {
// See <https://www.sqlite.org/c3ref/create_collation.html>
return sqlite3_stricmp(lhs.name, rhs.name) == 0
}
}

0 comments on commit c1f59df

Please sign in to comment.