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 the LegacySQLiteStore 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‘s addStorage() 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 different fileURL 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 (as InferredSchemaMappingProvider) and may be omitted from the array.

    localStorageOptions

    When the SQLiteStore is passed to the DataStack‘s addStorage() methods, tells the DataStack how to setup the persistent store. Defaults to .none.

  • Initializes an SQLite store interface from the given SQLite file name. When this instance is passed to the DataStack‘s addStorage() methods, a new SQLite file will be created if it does not exist.

    Warning

    The default SQLite file location for the LegacySQLiteStore 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.

    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 different fileName 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 (as InferredSchemaMappingProvider) and may be omitted from the array.

    localStorageOptions

    When the SQLiteStore is passed to the DataStack‘s addStorage() methods, tells the DataStack how to setup the persistent store. Defaults to .None.

  • Initializes an SQLiteStore with an all-default settings: a fileURL pointing to a “.sqlite” file in the “Application Support/” directory (or the “Caches/” directory on tvOS), a nil configuration pertaining to the “Default” configuration, a migrationMappingProviders set to empty, and localStorageOptions set to .AllowProgresiveMigration.

    Warning

    The default SQLite file location for the LegacySQLiteStore 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.

    Declaration

    Swift

    public init()
  • Initializes an SQLite store interface from the given SQLite file name. When this instance is passed to the DataStack‘s addStorage() methods, a new SQLite file will be created if it does not exist.

    Warning

    The default SQLite file location for the LegacySQLiteStore 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.

    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 different fileName 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 (as InferredSchemaMappingProvider) and may be omitted from the array.

    localStorageOptions

    When the SQLiteStore is passed to the DataStack‘s addStorage() methods, tells the DataStack how to setup the persistent store. Defaults to .None.

  • Initializes an LegacySQLiteStore with an all-default settings: a fileURL pointing to a “.sqlite” file in the “Application Support” directory (or the “Caches” directory on tvOS), a nil configuration pertaining to the “Default” configuration, a migrationMappingProviders set to empty, and localStorageOptions set to .AllowProgresiveMigration.

    Warning

    The default SQLite file location for the LegacySQLiteStore 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.

    Declaration

    Swift

    public static func legacy() -> SQLiteStore
  • Queries the file size (in bytes) of the store, or nil if the file does not exist yet

    Declaration

    Swift

    public func fileSize() -> UInt64?

StorageInterface

  • The string identifier for the NSPersistentStore‘s type property. For SQLiteStores, this is always set to NSSQLiteStoreType.

    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. For SQLiteStores, this is always set to

    [NSSQLitePragmasOption: ["journal_mode": "WAL"]]
    

    Declaration

    Swift

    public let storeOptions: [AnyHashable : Any]?
  • Do not call directly. Used by the DataStack internally.

    Declaration

    Swift

    public func cs_didAddToDataStack(_ dataStack: DataStack)
  • Do not call directly. Used by the DataStack internally.

    Declaration

    Swift

    public func cs_didRemoveFromDataStack(_ dataStack: DataStack)
  • The NSURL that points to the SQLite file

    Declaration

    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 store

    Declaration

    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. For SQLiteStore, 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! The sourceModel argument is a hint for the existing store’s model version. For SQLiteStore, 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

CustomDebugStringConvertible

  • Declaration

    Swift

    public var debugDescription: String { get }