Files
GRDB.swift/GRDB/Core/DatabaseSchemaCache.swift
T
Gwendal Roué 7c684d06c1 Simplify schema cache management
We don't need EmptyDatabaseSchemaCache. It does not help unsafe reads to work better if concurrent writes modify the schema anyway.
2020-03-01 15:51:37 +01:00

49 lines
1.4 KiB
Swift

/// A thread-unsafe database schema cache
struct DatabaseSchemaCache {
var schemaInfo: SchemaInfo?
private var primaryKeys: [String: PrimaryKeyInfo] = [:]
private var columns: [String: [ColumnInfo]] = [:]
private var indexes: [String: [IndexInfo]] = [:]
private var foreignKeys: [String: [ForeignKeyInfo]] = [:]
mutating func clear() {
primaryKeys = [:]
columns = [:]
indexes = [:]
foreignKeys = [:]
schemaInfo = nil
}
func primaryKey(_ table: String) -> PrimaryKeyInfo? {
return primaryKeys[table]
}
mutating func set(primaryKey: PrimaryKeyInfo, forTable table: String) {
primaryKeys[table] = primaryKey
}
func columns(in table: String) -> [ColumnInfo]? {
return columns[table]
}
mutating func set(columns: [ColumnInfo], forTable table: String) {
self.columns[table] = columns
}
func indexes(on table: String) -> [IndexInfo]? {
return indexes[table]
}
mutating func set(indexes: [IndexInfo], forTable table: String) {
self.indexes[table] = indexes
}
func foreignKeys(on table: String) -> [ForeignKeyInfo]? {
return foreignKeys[table]
}
mutating func set(foreignKeys: [ForeignKeyInfo], forTable table: String) {
self.foreignKeys[table] = foreignKeys
}
}