mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-15 21:53:39 +01:00
Merge branch 'develop' into prototype/Swift_3_2
This commit is contained in:
@@ -256,6 +256,21 @@ final class WhereTests: XCTestCase {
|
||||
XCTAssertEqual(andWhere.predicate, andPredicate)
|
||||
XCTAssertEqual(andWhere, whereClause1 && whereClause2 && whereClause3)
|
||||
}
|
||||
do {
|
||||
|
||||
let andWhere = whereClause1 && whereClause2 && whereClause3
|
||||
let noneWhere: Where? = nil
|
||||
let someWhere: Where? = Where("key4", isEqualTo: "value4")
|
||||
|
||||
|
||||
let finalNoneWhere = andWhere && noneWhere
|
||||
let finalSomeWhere = andWhere && someWhere
|
||||
let unwrappedFinalSomeWhere = andWhere && someWhere!
|
||||
|
||||
|
||||
XCTAssertEqual(andWhere.predicate, finalNoneWhere.predicate)
|
||||
XCTAssertEqual(finalSomeWhere.predicate, unwrappedFinalSomeWhere.predicate)
|
||||
}
|
||||
do {
|
||||
|
||||
let orWhere = whereClause1 || whereClause2 || whereClause3
|
||||
@@ -272,6 +287,21 @@ final class WhereTests: XCTestCase {
|
||||
XCTAssertEqual(orWhere.predicate, orPredicate)
|
||||
XCTAssertEqual(orWhere, whereClause1 || whereClause2 || whereClause3)
|
||||
}
|
||||
do {
|
||||
|
||||
let orWhere = whereClause1 || whereClause2 || whereClause3
|
||||
let noneWhere: Where? = nil
|
||||
let someWhere: Where? = Where("key4", isEqualTo: "value4")
|
||||
|
||||
|
||||
let finalNoneWhere = orWhere && noneWhere
|
||||
let finalSomeWhere = orWhere && someWhere
|
||||
let unwrappedFinalSomeWhere = orWhere && someWhere!
|
||||
|
||||
XCTAssertEqual(orWhere.predicate, finalNoneWhere.predicate)
|
||||
XCTAssertEqual(finalSomeWhere.predicate, unwrappedFinalSomeWhere.predicate)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@objc
|
||||
|
||||
@@ -868,7 +868,8 @@ extension SQLiteStore: CustomDebugStringConvertible, CoreStoreDebugStringConvert
|
||||
("storeOptions", self.storeOptions as Any),
|
||||
("fileURL", self.fileURL),
|
||||
("migrationMappingProviders", self.migrationMappingProviders),
|
||||
("localStorageOptions", self.localStorageOptions)
|
||||
("localStorageOptions", self.localStorageOptions),
|
||||
("fileSize", self.fileSize() as Any)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -707,6 +707,7 @@ public extension DataStack {
|
||||
|
||||
do {
|
||||
|
||||
try storage.cs_finalizeStorageAndWait(soureModelHint: sourceModel)
|
||||
try migrationManager.migrateStore(
|
||||
from: fileURL,
|
||||
sourceType: type(of: storage).storeType,
|
||||
@@ -716,6 +717,13 @@ public extension DataStack {
|
||||
destinationType: type(of: storage).storeType,
|
||||
destinationOptions: nil
|
||||
)
|
||||
let temporaryStorage = SQLiteStore(
|
||||
fileURL: temporaryFileURL,
|
||||
configuration: storage.configuration,
|
||||
migrationMappingProviders: storage.migrationMappingProviders,
|
||||
localStorageOptions: storage.localStorageOptions
|
||||
)
|
||||
try temporaryStorage.cs_finalizeStorageAndWait(soureModelHint: destinationModel)
|
||||
}
|
||||
catch {
|
||||
|
||||
|
||||
@@ -86,6 +86,11 @@ public final class LegacySQLiteStore: LocalStorage {
|
||||
|
||||
public var localStorageOptions: LocalStorageOptions
|
||||
|
||||
public func cs_finalizeStorageAndWait(soureModelHint: NSManagedObjectModel) throws {
|
||||
|
||||
fatalError()
|
||||
}
|
||||
|
||||
public func cs_eraseStorageAndWait(metadata: [String: Any], soureModelHint: NSManagedObjectModel?) throws {
|
||||
|
||||
fatalError()
|
||||
|
||||
@@ -117,6 +117,20 @@ public final class SQLiteStore: LocalStorage {
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
Queries the file size (in bytes) of the store, or `nil` if the file does not exist yet
|
||||
*/
|
||||
public func fileSize() -> UInt64? {
|
||||
|
||||
guard let attribute = try? FileManager.default.attributesOfItem(atPath: self.fileURL.path),
|
||||
let sizeAttribute = attribute[.size],
|
||||
let fileSize = sizeAttribute as? NSNumber else {
|
||||
|
||||
return nil
|
||||
}
|
||||
return fileSize.uint64Value
|
||||
}
|
||||
|
||||
|
||||
// MARK: StorageInterface
|
||||
|
||||
@@ -191,6 +205,22 @@ public final class SQLiteStore: LocalStorage {
|
||||
return storeOptions
|
||||
}
|
||||
|
||||
/**
|
||||
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.
|
||||
*/
|
||||
public func cs_finalizeStorageAndWait(soureModelHint: NSManagedObjectModel) throws {
|
||||
|
||||
_ = try withExtendedLifetime(NSPersistentStoreCoordinator(managedObjectModel: soureModelHint)) { (coordinator: NSPersistentStoreCoordinator) in
|
||||
|
||||
try coordinator.addPersistentStore(
|
||||
ofType: type(of: self).storeType,
|
||||
configurationName: self.configuration,
|
||||
at: fileURL,
|
||||
options: [NSSQLitePragmasOption: ["journal_mode": "DELETE"]]
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
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.
|
||||
*/
|
||||
|
||||
@@ -141,6 +141,11 @@ public protocol LocalStorage: StorageInterface {
|
||||
*/
|
||||
func dictionary(forOptions options: LocalStorageOptions) -> [AnyHashable: Any]?
|
||||
|
||||
/**
|
||||
Called by the `DataStack` to perform checkpoint operations on the storage. (SQLite stores for example, can convert the database's WAL journaling mode to DELETE to force a checkpoint)
|
||||
*/
|
||||
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. Implementers can use the `sourceModel` to perform necessary store operations. (SQLite stores for example, can convert WAL journaling mode to DELETE before deleting)
|
||||
*/
|
||||
|
||||
@@ -42,6 +42,40 @@ public struct Where: FetchClause, QueryClause, DeleteClause, Hashable {
|
||||
return Where(NSCompoundPredicate(type: .and, subpredicates: [left.predicate, right.predicate]))
|
||||
}
|
||||
|
||||
/**
|
||||
Combines two `Where` predicates together using `AND` operator.
|
||||
- parameter left: the left hand side `Where` clause
|
||||
- parameter right: the right hand side `Where` clause
|
||||
- returns: Return `left` unchanged if `right` is nil
|
||||
*/
|
||||
public static func && (left: Where, right: Where?) -> Where {
|
||||
|
||||
if right != nil {
|
||||
return left && right!
|
||||
}
|
||||
else {
|
||||
|
||||
return left
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Combines two `Where` predicates together using `AND` operator.
|
||||
- parameter left: the left hand side `Where` clause
|
||||
- parameter right: the right hand side `Where` clause
|
||||
- returns: Returns `right` unchanged if `left` is nil
|
||||
*/
|
||||
public static func && (left: Where?, right: Where) -> Where {
|
||||
|
||||
if left != nil {
|
||||
return left && right
|
||||
}
|
||||
else {
|
||||
|
||||
return right
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Combines two `Where` predicates together using `OR` operator
|
||||
*/
|
||||
@@ -50,6 +84,40 @@ public struct Where: FetchClause, QueryClause, DeleteClause, Hashable {
|
||||
return Where(NSCompoundPredicate(type: .or, subpredicates: [left.predicate, right.predicate]))
|
||||
}
|
||||
|
||||
/**
|
||||
Combines two `Where` predicates together using `OR` operator.
|
||||
- parameter left: the left hand side `Where` clause
|
||||
- parameter right: the right hand side `Where` clause
|
||||
- returns: Returns `left` unchanged if `right` is nil
|
||||
*/
|
||||
public static func || (left: Where, right: Where?) -> Where {
|
||||
|
||||
if right != nil {
|
||||
return left || right!
|
||||
}
|
||||
else {
|
||||
|
||||
return left
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Combines two `Where` predicates together using `OR` operator.
|
||||
- parameter left: the left hand side `Where` clause
|
||||
- parameter right: the right hand side `Where` clause
|
||||
- returns: Return `right` unchanged if `left` is nil
|
||||
*/
|
||||
public static func || (left: Where?, right: Where) -> Where {
|
||||
|
||||
if left != nil {
|
||||
return left || right
|
||||
}
|
||||
else {
|
||||
|
||||
return right
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Inverts the predicate of a `Where` clause using `NOT` operator
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user