SQLiteStore
public final class SQLiteStore : LocalStorage
extension SQLiteStore: CustomDebugStringConvertible, CoreStoreDebugStringConvertible
A storage interface that is backed by an SQLite database.
Warning
The default SQLite file location for theLegacySQLiteStore
and SQLiteStore
are different. If the app was depending on CoreStore’s default directories prior to 2.0.0, make sure to use the SQLiteStore.legacy(...)
factory methods to create the SQLiteStore
instead of using initializers directly.
-
Initializes an SQLite store interface from the given SQLite file URL. When this instance is passed to the
DataStack
‘saddStorage()
methods, a new SQLite file will be created if it does not exist.Declaration
Swift
public init(fileURL: URL, configuration: ModelConfiguration = nil, migrationMappingProviders: [SchemaMappingProvider] = [], localStorageOptions: LocalStorageOptions = nil)
Parameters
fileURL
the local file URL for the target SQLite persistent store. Note that if you have multiple configurations, you will need to specify a different
fileURL
explicitly for each of them.configuration
an optional configuration name from the model file. If not specified, defaults to
nil
, the “Default” configuration. Note that if you have multiple configurations, you will need to specify a differentfileURL
explicitly for each of them.migrationMappingProviders
an array of
SchemaMappingProviders
that provides the complete mapping models for custom migrations. All lightweight inferred mappings and/or migration mappings provided by *xcmappingmodel files are automatically used as fallback (asInferredSchemaMappingProvider
) and may be omitted from the array.localStorageOptions
-
Initializes an SQLite store interface from the given SQLite file name. When this instance is passed to the
DataStack
‘saddStorage()
methods, a new SQLite file will be created if it does not exist.Warning
The default SQLite file location for theLegacySQLiteStore
andSQLiteStore
are different. If the app was depending on CoreStore’s default directories prior to 2.0.0, make sure to use theSQLiteStore.legacy(...)
factory methods to create theSQLiteStore
instead of using initializers directly.Declaration
Swift
public init(fileName: String, configuration: ModelConfiguration = nil, migrationMappingProviders: [SchemaMappingProvider] = [], localStorageOptions: LocalStorageOptions = nil)
Parameters
fileName
the local filename for the SQLite persistent store in the “Application Support/
” directory (or the “Caches/ ” directory on tvOS). Note that if you have multiple configurations, you will need to specify a different fileName
explicitly for each of them.configuration
an optional configuration name from the model file. If not specified, defaults to
nil
, the “Default” configuration. Note that if you have multiple configurations, you will need to specify a differentfileName
explicitly for each of them.migrationMappingProviders
an array of
SchemaMappingProviders
that provides the complete mapping models for custom migrations. All lightweight inferred mappings and/or migration mappings provided by *xcmappingmodel files are automatically used as fallback (asInferredSchemaMappingProvider
) and may be omitted from the array.localStorageOptions
-
Initializes an
SQLiteStore
with an all-default settings: afileURL
pointing to a “.sqlite” file in the “Application Support/ ” directory (or the “Caches/ ” directory on tvOS), a nil
configuration
pertaining to the “Default” configuration, amigrationMappingProviders
set to empty, andlocalStorageOptions
set to.AllowProgresiveMigration
.Warning
The default SQLite file location for theLegacySQLiteStore
andSQLiteStore
are different. If the app was depending on CoreStore’s default directories prior to 2.0.0, make sure to use theSQLiteStore.legacy(...)
factory methods to create theSQLiteStore
instead of using initializers directly.Declaration
Swift
public init()
-
Initializes an SQLite store interface from the given SQLite file name. When this instance is passed to the
DataStack
‘saddStorage()
methods, a new SQLite file will be created if it does not exist.Warning
The default SQLite file location for theLegacySQLiteStore
andSQLiteStore
are different. If the app was depending on CoreStore’s default directories prior to 2.0.0, make sure to use theSQLiteStore.legacy(...)
factory methods to create theSQLiteStore
instead of using initializers directly.Declaration
Swift
public static func legacy(fileName: String, configuration: ModelConfiguration = nil, migrationMappingProviders: [SchemaMappingProvider] = [], localStorageOptions: LocalStorageOptions = nil) -> SQLiteStore
Parameters
legacyFileName
the local filename for the SQLite persistent store in the “Application Support” directory (or the “Caches” directory on tvOS). Note that if you have multiple configurations, you will need to specify a different
fileName
explicitly for each of them.configuration
an optional configuration name from the model file. If not specified, defaults to
nil
, the “Default” configuration. Note that if you have multiple configurations, you will need to specify a differentfileName
explicitly for each of them.migrationMappingProviders
an array of
SchemaMappingProviders
that provides the complete mapping models for custom migrations. All lightweight inferred mappings and/or migration mappings provided by *xcmappingmodel files are automatically used as fallback (asInferredSchemaMappingProvider
) and may be omitted from the array.localStorageOptions
-
Initializes an
LegacySQLiteStore
with an all-default settings: afileURL
pointing to a “.sqlite” file in the “Application Support” directory (or the “Caches” directory on tvOS), a nil
configuration
pertaining to the “Default” configuration, amigrationMappingProviders
set to empty, andlocalStorageOptions
set to.AllowProgresiveMigration
.Warning
The default SQLite file location for theLegacySQLiteStore
andSQLiteStore
are different. If the app was depending on CoreStore’s default directories prior to 2.0.0, make sure to use theSQLiteStore.legacy(...)
factory methods to create theSQLiteStore
instead of using initializers directly.Declaration
Swift
public static func legacy() -> SQLiteStore
-
Queries the file size (in bytes) of the store, or
nil
if the file does not exist yetDeclaration
Swift
public func fileSize() -> UInt64?
-
The string identifier for the
NSPersistentStore
‘stype
property. ForSQLiteStore
s, this is always set toNSSQLiteStoreType
.Declaration
Swift
public static let storeType: String
-
The configuration name in the model file
Declaration
Swift
public let configuration: ModelConfiguration
-
The options dictionary for the
NSPersistentStore
. ForSQLiteStore
s, this is always set to[NSSQLitePragmasOption: ["journal_mode": "WAL"]]
Declaration
Swift
public let storeOptions: [AnyHashable : Any]?
-
The
NSURL
that points to the SQLite fileDeclaration
Swift
public let fileURL: URL
-
An array of
SchemaMappingProviders
that provides the complete mapping models for custom migrations.Declaration
Swift
public let migrationMappingProviders: [SchemaMappingProvider]
-
Options that tell the
DataStack
how to setup the persistent storeDeclaration
Swift
public var localStorageOptions: LocalStorageOptions
-
The options dictionary for the specified
LocalStorageOptions
Declaration
Swift
public func dictionary(forOptions options: LocalStorageOptions) -> [AnyHashable : Any]?
-
Called by the
DataStack
to perform checkpoint operations on the storage. ForSQLiteStore
, this converts the database’s WAL journaling mode to DELETE to force a checkpoint.Declaration
Swift
public func cs_finalizeStorageAndWait(soureModelHint: NSManagedObjectModel) throws
-
Called by the
DataStack
to perform actual deletion of the store file from disk. Do not call directly! ThesourceModel
argument is a hint for the existing store’s model version. ForSQLiteStore
, this converts the database’s WAL journaling mode to DELETE before deleting the file.Declaration
Swift
public func cs_eraseStorageAndWait(metadata: [String : Any], soureModelHint: NSManagedObjectModel?) throws
-
Declaration
Swift
public var debugDescription: String { get }