From ed32e44bc21aeb010d685109f8b3f790348db00c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Wed, 23 Dec 2020 10:31:16 +0100 Subject: [PATCH] DRY --- GRDB/Core/Database+Schema.swift | 26 ++++++++++++++++++++++---- GRDB/Core/DatabaseRegion.swift | 5 ++--- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/GRDB/Core/Database+Schema.swift b/GRDB/Core/Database+Schema.swift index 3cd5fc7c9..3b071579f 100644 --- a/GRDB/Core/Database+Schema.swift +++ b/GRDB/Core/Database+Schema.swift @@ -35,26 +35,44 @@ extension Database { /// Returns whether a table is an internal SQLite table. /// - /// Those are tables whose name begins with "sqlite_". + /// Those are tables whose name begins with `sqlite_` and `pragma_`. /// /// For more information, see https://www.sqlite.org/fileformat2.html - public func isSQLiteInternalTable(_ tableName: String) -> Bool { + public static func isSQLiteInternalTable(_ tableName: String) -> Bool { // https://www.sqlite.org/fileformat2.html#internal_schema_objects // > The names of internal schema objects always begin with "sqlite_" // > and any table, index, view, or trigger whose name begins with // > "sqlite_" is an internal schema object. SQLite prohibits // > applications from creating objects whose names begin with // > "sqlite_". - return tableName.starts(with: "sqlite_") + tableName.starts(with: "sqlite_") || tableName.starts(with: "pragma_") + } + + /// Returns whether a table is an internal SQLite table. + /// + /// Those are tables whose name begins with `sqlite_` and `pragma_`. + /// + /// For more information, see https://www.sqlite.org/fileformat2.html + @available(*, deprecated, message: "Use Database.isSQLiteInternalTable(_:) static method instead.") + public func isSQLiteInternalTable(_ tableName: String) -> Bool { + Self.isSQLiteInternalTable(tableName) } /// Returns whether a table is an internal GRDB table. /// /// Those are tables whose name begins with "grdb_". - public func isGRDBInternalTable(_ tableName: String) -> Bool { + public static func isGRDBInternalTable(_ tableName: String) -> Bool { tableName.starts(with: "grdb_") } + /// Returns whether a table is an internal GRDB table. + /// + /// Those are tables whose name begins with "grdb_". + @available(*, deprecated, message: "Use Database.isGRDBInternalTable(_:) static method instead.") + public func isGRDBInternalTable(_ tableName: String) -> Bool { + Self.isGRDBInternalTable(tableName) + } + /// Returns whether a view exists. public func viewExists(_ name: String) throws -> Bool { try exists(type: .view, name: name) diff --git a/GRDB/Core/DatabaseRegion.swift b/GRDB/Core/DatabaseRegion.swift index 6b301e64e..8e61ddd94 100644 --- a/GRDB/Core/DatabaseRegion.swift +++ b/GRDB/Core/DatabaseRegion.swift @@ -161,12 +161,11 @@ public struct DatabaseRegion: CustomStringConvertible, Equatable { return DatabaseRegion(tableRegions: filteredRegions) } - /// Returns a region which doesn't contain any SQLite internal table or - /// pragma table. + /// Returns a region which doesn't contain any SQLite internal table. func ignoringInternalSQLiteTables() -> DatabaseRegion { guard let tableRegions = tableRegions else { return .fullDatabase } let filteredRegions = tableRegions.filter { - !$0.key.starts(with: "sqlite_") && !$0.key.starts(with: "pragma_") + !Database.isSQLiteInternalTable($0.key) } return DatabaseRegion(tableRegions: filteredRegions) }