mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-26 04:07:50 +00:00
DRY
This commit is contained in:
1 parent
60a9494434
commit
ed32e44bc2
2 files changed
+24
-7
No files matched your search
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user