# 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.

- `init(fileURL:configuration:migrationMappingProviders:localStorageOptions:)`

  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`.

- `init(fileName:configuration:migrationMappingProviders:localStorageOptions:)`

  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/<bundle id>” directory (or the “Caches/<bundle id>” 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`.

- `init()`

  Initializes an `SQLiteStore` with an all-default settings: a `fileURL` pointing to a “<Application name>.sqlite” file in the “Application Support/<bundle id>” directory (or the “Caches/<bundle id>” 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()

- `legacy(fileName:configuration:migrationMappingProviders:localStorageOptions:)`

  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`.

- `legacy()`

  Initializes an `LegacySQLiteStore` with an all-default settings: a `fileURL` pointing to a “<Application name>.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

- `fileSize()`

  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

- `storeType`

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

  #### Declaration

  Swift

      public static let storeType: String

- `configuration`

  The configuration name in the model file

  #### Declaration

  Swift

      public let configuration: ModelConfiguration

- `storeOptions`

  The options dictionary for the `NSPersistentStore`. For `SQLiteStore`s, this is always set to

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

  #### Declaration

  Swift

      public let storeOptions: [AnyHashable : Any]?

- `cs_didAddToDataStack(_:)`

  Do not call directly. Used by the `DataStack` internally.

  #### Declaration

  Swift

      public func cs_didAddToDataStack(_ dataStack: DataStack)

- `cs_didRemoveFromDataStack(_:)`

  Do not call directly. Used by the `DataStack` internally.

  #### Declaration

  Swift

      public func cs_didRemoveFromDataStack(_ dataStack: DataStack)

- `fileURL`

  The `NSURL` that points to the SQLite file

  #### Declaration

  Swift

      public let fileURL: URL

- `migrationMappingProviders`

  An array of `SchemaMappingProviders` that provides the complete mapping models for custom migrations.

  #### Declaration

  Swift

      public let migrationMappingProviders: [SchemaMappingProvider]

- `localStorageOptions`

  Options that tell the `DataStack` how to setup the persistent store

  #### Declaration

  Swift

      public var localStorageOptions: LocalStorageOptions

- `dictionary(forOptions:)`

  The options dictionary for the specified `LocalStorageOptions`

  #### Declaration

  Swift

      public func dictionary(forOptions options: LocalStorageOptions) -> [AnyHashable : Any]?

- `cs_finalizeStorageAndWait(soureModelHint:)`

  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

- `cs_eraseStorageAndWait(metadata:soureModelHint:)`

  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

- `debugDescription`

  #### Declaration

  Swift

      public var debugDescription: String { get }