# BaseDataTransaction

    public class BaseDataTransaction

    extension BaseDataTransaction: FetchableSource, QueryableSource

The `BaseDataTransaction` is an abstract interface for `NSManagedObject` creates, updates, and deletes. All `BaseDataTransaction` subclasses manage a private `NSManagedObjectContext` which are direct children of the `NSPersistentStoreCoordinator`‘s root `NSManagedObjectContext`. This means that all updates are saved first to the persistent store, and then propagated up to the read-only `NSManagedObjectContext`.

### Object management

- `hasChanges`

  Indicates if the transaction has pending changes

  #### Declaration

  Swift

      public var hasChanges: Bool { get }

- `create(_:)`

  Creates a new `NSManagedObject` or `CoreStoreObject` with the specified entity type.

  #### Declaration

  Swift

      public func create<O>(_ into: Into<O>) -> O where O : DynamicObject

  #### Parameters

  `into` | the `Into` clause indicating the destination `NSManagedObject` or `CoreStoreObject` entity type and the destination configuration

  #### Return Value

  a new `NSManagedObject` or `CoreStoreObject` instance of the specified entity type.

- `edit(_:)`

  Returns an editable proxy of a specified `NSManagedObject` or `CoreStoreObject`.

  #### Declaration

  Swift

      public func edit<O>(_ object: O?) -> O? where O : DynamicObject

  #### Parameters

  `object` | the `NSManagedObject` or `CoreStoreObject` type to be edited

  #### Return Value

  an editable proxy for the specified `NSManagedObject` or `CoreStoreObject`.

- `edit(_:_:)`

  Returns an editable proxy of the object with the specified `NSManagedObjectID`.

  #### Declaration

  Swift

      public func edit<O>(_ into: Into<O>, _ objectID: NSManagedObjectID) -> O? where O : DynamicObject

  #### Parameters

  `into` | an `Into` clause specifying the entity type
  `objectID` | the `NSManagedObjectID` for the object to be edited

  #### Return Value

  an editable proxy for the specified `NSManagedObject` or `CoreStoreObject`.

- `delete(objectIDs:)`

  Deletes the objects with the specified `NSManagedObjectID`s.

  #### Declaration

  Swift

      public func delete<S>(objectIDs: S) where S : Sequence, S.Element : NSManagedObjectID

  #### Parameters

  `objectIDs` | the `NSManagedObjectID`s of the objects to delete

- `delete(_:_:)`

  Deletes the specified `NSManagedObject`s or `CoreStoreObject`s represented by series of `ObjectRepresentation`s.

  #### Declaration

  Swift

      public func delete<O>(_ object: O?, _ objects: O?...) where O : ObjectRepresentation

  #### Parameters

  `object` | the `ObjectRepresentation` representing an `NSManagedObject` or `CoreStoreObject` to be deleted
  `objects` | other `ObjectRepresentation`s representing `NSManagedObject`s or `CoreStoreObject`s to be deleted

- `delete(_:)`

  Deletes the specified `NSManagedObject`s or `CoreStoreObject`s represented by an `ObjectRepresenation`.

  #### Declaration

  Swift

      public func delete<S>(_ objects: S) where S : Sequence, S.Element : ObjectRepresentation

  #### Parameters

  `objects` | the `ObjectRepresenation`s representing `NSManagedObject`s or `CoreStoreObject`s to be deleted

- `refreshAndMergeAllObjects()`

  Refreshes all registered objects `NSManagedObject`s in the transaction.

  #### Declaration

  Swift

      public func refreshAndMergeAllObjects()

### Inspecting Pending Objects

- `objectHasPersistentChangedValues(_:)`

  Returns `true` if the object has any property values changed. This method should not be called after the `commit()` method was called.

  #### Declaration

  Swift

      public func objectHasPersistentChangedValues<O>(_ object: O) -> Bool where O : DynamicObject

  #### Parameters

  `object` | the `DynamicObject` instance

  #### Return Value

  `true` if the object has any property values changed.

- `insertedObjects(_:)`

  Returns all pending `DynamicObject`s of the specified type that were inserted to the transaction. This method should not be called after the `commit()` method was called.

  #### Declaration

  Swift

      public func insertedObjects<O>(_ entity: O.Type) -> Set<O> where O : DynamicObject, O : Hashable

  #### Parameters

  `entity` | the `DynamicObject` subclass to filter

  #### Return Value

  a `Set` of pending `DynamicObject`s of the specified type that were inserted to the transaction.

- `insertedObjectIDs()`

  Returns all pending `NSManagedObjectID`s that were inserted to the transaction. This method should not be called after the `commit()` method was called.

  #### Declaration

  Swift

      public func insertedObjectIDs() -> Set<NSManagedObjectID>

  #### Return Value

  a `Set` of pending `NSManagedObjectID`s that were inserted to the transaction.

- `insertedObjectIDs(_:)`

  Returns all pending `NSManagedObjectID`s of the specified type that were inserted to the transaction. This method should not be called after the `commit()` method was called.

  #### Declaration

  Swift

      public func insertedObjectIDs<O>(_ entity: O.Type) -> Set<NSManagedObjectID> where O : DynamicObject

  #### Parameters

  `entity` | the `DynamicObject` subclass to filter

  #### Return Value

  a `Set` of pending `NSManagedObjectID`s of the specified type that were inserted to the transaction.

- `updatedObjects(_:)`

  Returns all pending `DynamicObject`s of the specified type that were updated in the transaction. This method should not be called after the `commit()` method was called.

  #### Declaration

  Swift

      public func updatedObjects<O>(_ entity: O.Type) -> Set<O> where O : DynamicObject, O : Hashable

  #### Parameters

  `entity` | the `DynamicObject` subclass to filter

  #### Return Value

  a `Set` of pending `DynamicObject`s of the specified type that were updated in the transaction.

- `updatedObjectIDs()`

  Returns all pending `NSManagedObjectID`s that were updated in the transaction. This method should not be called after the `commit()` method was called.

  #### Declaration

  Swift

      public func updatedObjectIDs() -> Set<NSManagedObjectID>

  #### Return Value

  a `Set` of pending `NSManagedObjectID`s that were updated in the transaction.

- `updatedObjectIDs(_:)`

  Returns all pending `NSManagedObjectID`s of the specified type that were updated in the transaction. This method should not be called after the `commit()` method was called.

  #### Declaration

  Swift

      public func updatedObjectIDs<O>(_ entity: O.Type) -> Set<NSManagedObjectID> where O : DynamicObject

  #### Parameters

  `entity` | the `DynamicObject` subclass to filter

  #### Return Value

  a `Set` of pending `NSManagedObjectID`s of the specified type that were updated in the transaction.

- `deletedObjects(_:)`

  Returns all pending `DynamicObject`s of the specified type that were deleted from the transaction. This method should not be called after the `commit()` method was called.

  #### Declaration

  Swift

      public func deletedObjects<O>(_ entity: O.Type) -> Set<O> where O : DynamicObject, O : Hashable

  #### Parameters

  `entity` | the `DynamicObject` subclass to filter

  #### Return Value

  a `Set` of pending `DynamicObject`s of the specified type that were deleted from the transaction.

- `deletedObjectIDs()`

  Returns all pending `NSManagedObjectID`s of the specified type that were deleted from the transaction. This method should not be called after the `commit()` method was called.

  #### Declaration

  Swift

      public func deletedObjectIDs() -> Set<NSManagedObjectID>

  #### Parameters

  `entity` | the `DynamicObject` subclass to filter

  #### Return Value

  a `Set` of pending `NSManagedObjectID`s of the specified type that were deleted from the transaction.

- `deletedObjectIDs(_:)`

  Returns all pending `NSManagedObjectID`s of the specified type that were deleted from the transaction. This method should not be called after the `commit()` method was called.

  #### Declaration

  Swift

      public func deletedObjectIDs<O>(_ entity: O.Type) -> Set<NSManagedObjectID> where O : DynamicObject

  #### Parameters

  `entity` | the `DynamicObject` subclass to filter

  #### Return Value

  a `Set` of pending `NSManagedObjectID`s of the specified type that were deleted from the transaction.

### 3rd Party Utilities

- `sourceIdentifier`

  An arbitrary value that identifies the source of this transaction. Callers of the transaction can provide this value through the `DataStack.perform(...)` methods.

  #### Declaration

  Swift

      public let sourceIdentifier: Any?

- `userInfo`

  Allow external libraries to store custom data in the transaction. App code should rarely have a need for this.

      enum Static {
         static var myDataKey: Void?
      }
      transaction.userInfo[&Static.myDataKey] = myObject

  Important

  Do not use this method to store thread-sensitive data.

  #### Declaration

  Swift

      public let userInfo: UserInfo

### BaseDataTransaction

- `importObject(_:source:)`

  Creates an `ImportableObject` by importing from the specified import source.

  Throws

  an `Error` thrown from any of the `ImportableObject` methods

  #### Declaration

  Swift

      public func importObject<O: ImportableObject>(
          _ into: Into<O>,
          source: O.ImportSource) throws -> O?

  #### Parameters

  `into` | an `Into` clause specifying the entity type
  `source` | the object to import values from

  #### Return Value

  the created `ImportableObject` instance, or `nil` if the import was ignored

- `importObject(_:source:)`

  Updates an existing `ImportableObject` by importing values from the specified import source.

  Throws

  an `Error` thrown from any of the `ImportableObject` methods

  #### Declaration

  Swift

      public func importObject<O: ImportableObject>(
          _ object: O,
          source: O.ImportSource) throws

  #### Parameters

  `object` | the `ImportableObject` to update
  `source` | the object to import values from

- `importObjects(_:sourceArray:)`

  Creates multiple `ImportableObject`s by importing from the specified array of import sources.

  Throws

  an `Error` thrown from any of the `ImportableObject` methods

  #### Declaration

  Swift

      public func importObjects<O: ImportableObject, S: Sequence>(
          _ into: Into<O>,
          sourceArray: S) throws -> [O] where S.Iterator.Element == O.ImportSource

  #### Parameters

  `into` | an `Into` clause specifying the entity type
  `sourceArray` | the array of objects to import values from

  #### Return Value

  the array of created `ImportableObject` instances

- `importUniqueObject(_:source:)`

  Updates an existing `ImportableUniqueObject` or creates a new instance by importing from the specified import source.

  Throws

  an `Error` thrown from any of the `ImportableUniqueObject` methods

  #### Declaration

  Swift

      public func importUniqueObject<O: ImportableUniqueObject>(
          _ into: Into<O>,
          source: O.ImportSource) throws -> O?

  #### Parameters

  `into` | an `Into` clause specifying the entity type
  `source` | the object to import values from

  #### Return Value

  the created/updated `ImportableUniqueObject` instance, or `nil` if the import was ignored

- `importUniqueObjects(_:sourceArray:preProcess:)`

  Updates existing `ImportableUniqueObject`s or creates them by importing from the specified array of import sources. `ImportableUniqueObject` methods are called on the objects in the same order as they are in the `sourceArray`, and are returned in an array with that same order.

  Warning

  If `sourceArray` contains multiple import sources with same ID, only the last `ImportSource` of the duplicates will be imported.

  Throws

  an `Error` thrown from any of the `ImportableUniqueObject` methods

  #### Declaration

  Swift

      public func importUniqueObjects<O: ImportableUniqueObject, S: Sequence>(
          _ into: Into<O>,
          sourceArray: S,
          preProcess: @escaping (_ mapping: [O.UniqueIDType: O.ImportSource]) throws -> [O.UniqueIDType: O.ImportSource] = { $0 }) throws -> [O] where S.Iterator.Element == O.ImportSource

  #### Parameters

  `into` | an `Into` clause specifying the entity type
  `sourceArray` | the array of objects to import values from
  `preProcess` | a closure that lets the caller tweak the internal `UniqueIDType`-to-`ImportSource` mapping to be used for importing. Callers can remove from/add to/update `mapping` and return the updated array from the closure.

  #### Return Value

  the array of created/updated `ImportableUniqueObject` instances

### DataTransaction

- `deleteAll(_:_:)`

  Deletes all `DynamicObject`s that satisfy the specified `DeleteClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.

  #### Declaration

  Swift

      @discardableResult
      public func deleteAll<O>(_ from: From<O>, _ deleteClauses: DeleteClause...) throws -> Int where O : DynamicObject

  #### Parameters

  `from` | a `From` clause indicating the entity type
  `deleteClauses` | a series of `DeleteClause` instances for the delete request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.

  #### Return Value

  the number of `DynamicObject`s deleted

- `deleteAll(_:_:)`

  Deletes all `DynamicObject`s that satisfy the specified `DeleteClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.

  #### Declaration

  Swift

      @discardableResult
      public func deleteAll<O>(_ from: From<O>, _ deleteClauses: [DeleteClause]) throws -> Int where O : DynamicObject

  #### Parameters

  `from` | a `From` clause indicating the entity type
  `deleteClauses` | a series of `DeleteClause` instances for the delete request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.

  #### Return Value

  the number of `DynamicObject`s deleted

- `deleteAll(_:)`

  Deletes all `DynamicObject`s that satisfy the specified conditions.

      transaction.deleteAll(From<Person>().where(\.age > 50))

  #### Declaration

  Swift

      @discardableResult
      public func deleteAll<B>(_ clauseChain: B) throws -> Int where B : FetchChainableBuilderType

  #### Parameters

  `clauseChain` | a `FetchChainableBuilderType` clause chain created from a `From` clause

  #### Return Value

  the number of `DynamicObject`s deleted

### FetchableSource

- `fetchExisting(_:)`

  Fetches the `DynamicObject` instance in the transaction’s context from a reference created from a transaction or from a different managed object context.

  #### Declaration

  Swift

      public func fetchExisting<O>(_ object: O) -> O? where O : DynamicObject

  #### Parameters

  `object` | a reference to the object created/fetched outside the transaction

  #### Return Value

  the `DynamicObject` instance if the object exists in the transaction, or `nil` if not found.

- `fetchExisting(_:)`

  Fetches the `DynamicObject` instance in the transaction’s context from an `NSManagedObjectID`.

  #### Declaration

  Swift

      public func fetchExisting<O>(_ objectID: NSManagedObjectID) -> O? where O : DynamicObject

  #### Parameters

  `objectID` | the `NSManagedObjectID` for the object

  #### Return Value

  the `DynamicObject` instance if the object exists in the transaction, or `nil` if not found.

- `fetchExisting(_:)`

  Fetches the `DynamicObject` instances in the transaction’s context from references created from a transaction or from a different managed object context.

  #### Declaration

  Swift

      public func fetchExisting<O, S>(_ objects: S) -> [O] where O : DynamicObject, O == S.Element, S : Sequence

  #### Parameters

  `objects` | an array of `DynamicObject`s created/fetched outside the transaction

  #### Return Value

  the `DynamicObject` array for objects that exists in the transaction

- `fetchExisting(_:)`

  Fetches the `DynamicObject` instances in the transaction’s context from a list of `NSManagedObjectID`.

  #### Declaration

  Swift

      public func fetchExisting<O, S>(_ objectIDs: S) -> [O] where O : DynamicObject, S : Sequence, S.Element == NSManagedObjectID

  #### Parameters

  `objectIDs` | the `NSManagedObjectID` array for the objects

  #### Return Value

  the `DynamicObject` array for objects that exists in the transaction

- `fetchOne(_:_:)`

  Fetches the first `DynamicObject` instance that satisfies the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.

  Throws

  `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store’s schema.

  #### Declaration

  Swift

      public func fetchOne<O>(_ from: From<O>, _ fetchClauses: FetchClause...) throws -> O? where O : DynamicObject

  #### Parameters

  `from` | a `From` clause indicating the entity type
  `fetchClauses` | a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.

  #### Return Value

  the first `DynamicObject` instance that satisfies the specified `FetchClause`s, or `nil` if no match was found

- `fetchOne(_:_:)`

  Fetches the first `DynamicObject` instance that satisfies the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.

  Throws

  `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store’s schema.

  #### Declaration

  Swift

      public func fetchOne<O>(_ from: From<O>, _ fetchClauses: [FetchClause]) throws -> O? where O : DynamicObject

  #### Parameters

  `from` | a `From` clause indicating the entity type
  `fetchClauses` | a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.

  #### Return Value

  the first `DynamicObject` instance that satisfies the specified `FetchClause`s, or `nil` if no match was found

- `fetchOne(_:)`

  Fetches the first `DynamicObject` instance that satisfies the specified `FetchChainableBuilderType` built from a chain of clauses.

      let youngestTeen = transaction.fetchOne(
          From<MyPersonEntity>()
              .where(\.age > 18)
              .orderBy(.ascending(\.age))
      )

  Throws

  `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store’s schema.

  #### Declaration

  Swift

      public func fetchOne<B>(_ clauseChain: B) throws -> B.ObjectType? where B : FetchChainableBuilderType

  #### Parameters

  `clauseChain` | a `FetchChainableBuilderType` built from a chain of clauses

  #### Return Value

  the first `DynamicObject` instance that satisfies the specified `FetchChainableBuilderType`, or `nil` if no match was found

- `fetchAll(_:_:)`

  Fetches all `DynamicObject` instances that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.

  Throws

  `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store’s schema.

  #### Declaration

  Swift

      public func fetchAll<O>(_ from: From<O>, _ fetchClauses: FetchClause...) throws -> [O] where O : DynamicObject

  #### Parameters

  `from` | a `From` clause indicating the entity type
  `fetchClauses` | a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.

  #### Return Value

  all `DynamicObject` instances that satisfy the specified `FetchClause`s, or an empty array if no match was found

- `fetchAll(_:_:)`

  Fetches all `DynamicObject` instances that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.

  Throws

  `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store’s schema.

  #### Declaration

  Swift

      public func fetchAll<O>(_ from: From<O>, _ fetchClauses: [FetchClause]) throws -> [O] where O : DynamicObject

  #### Parameters

  `from` | a `From` clause indicating the entity type
  `fetchClauses` | a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.

  #### Return Value

  all `DynamicObject` instances that satisfy the specified `FetchClause`s, or an empty array if no match was found

- `fetchAll(_:)`

  Fetches all `DynamicObject` instances that satisfy the specified `FetchChainableBuilderType` built from a chain of clauses.

      let people = transaction.fetchAll(
          From<MyPersonEntity>()
              .where(\.age > 18)
              .orderBy(.ascending(\.age))
      )

  Throws

  `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store’s schema.

  #### Declaration

  Swift

      public func fetchAll<B>(_ clauseChain: B) throws -> [B.ObjectType] where B : FetchChainableBuilderType

  #### Parameters

  `clauseChain` | a `FetchChainableBuilderType` built from a chain of clauses

  #### Return Value

  all `DynamicObject` instances that satisfy the specified `FetchChainableBuilderType`, or an empty array if no match was found

- `fetchCount(_:_:)`

  Fetches the number of `DynamicObject`s that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.

  Throws

  `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store’s schema.

  #### Declaration

  Swift

      public func fetchCount<O>(_ from: From<O>, _ fetchClauses: FetchClause...) throws -> Int where O : DynamicObject

  #### Parameters

  `from` | a `From` clause indicating the entity type
  `fetchClauses` | a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.

  #### Return Value

  the number of `DynamicObject`s that satisfy the specified `FetchClause`s

- `fetchCount(_:_:)`

  Fetches the number of `DynamicObject`s that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.

  Throws

  `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store’s schema.

  #### Declaration

  Swift

      public func fetchCount<O>(_ from: From<O>, _ fetchClauses: [FetchClause]) throws -> Int where O : DynamicObject

  #### Parameters

  `from` | a `From` clause indicating the entity type
  `fetchClauses` | a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.

  #### Return Value

  the number of `DynamicObject`s that satisfy the specified `FetchClause`s

- `fetchCount(_:)`

  Fetches the number of `DynamicObject`s that satisfy the specified `FetchChainableBuilderType` built from a chain of clauses.

      let numberOfAdults = transaction.fetchCount(
          From<MyPersonEntity>()
              .where(\.age > 18)
              .orderBy(.ascending(\.age))
      )

  Throws

  `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store’s schema.

  #### Declaration

  Swift

      public func fetchCount<B>(_ clauseChain: B) throws -> Int where B : FetchChainableBuilderType

  #### Parameters

  `clauseChain` | a `FetchChainableBuilderType` built from a chain of clauses

  #### Return Value

  the number of `DynamicObject`s that satisfy the specified `FetchChainableBuilderType`

- `fetchObjectID(_:_:)`

  Fetches the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.

  Throws

  `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store’s schema.

  #### Declaration

  Swift

      public func fetchObjectID<O>(_ from: From<O>, _ fetchClauses: FetchClause...) throws -> NSManagedObjectID? where O : DynamicObject

  #### Parameters

  `from` | a `From` clause indicating the entity type
  `fetchClauses` | a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.

  #### Return Value

  the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s, or `nil` if no match was found

- `fetchObjectID(_:_:)`

  Fetches the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.

  Throws

  `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store’s schema.

  #### Declaration

  Swift

      public func fetchObjectID<O>(_ from: From<O>, _ fetchClauses: [FetchClause]) throws -> NSManagedObjectID? where O : DynamicObject

  #### Parameters

  `from` | a `From` clause indicating the entity type
  `fetchClauses` | a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.

  #### Return Value

  the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s, or `nil` if no match was found

- `fetchObjectID(_:)`

  Fetches the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchChainableBuilderType` built from a chain of clauses.

      let youngestTeenID = transaction.fetchObjectID(
          From<MyPersonEntity>()
              .where(\.age > 18)
              .orderBy(.ascending(\.age))
      )

  Throws

  `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store’s schema.

  #### Declaration

  Swift

      public func fetchObjectID<B>(_ clauseChain: B) throws -> NSManagedObjectID? where B : FetchChainableBuilderType

  #### Parameters

  `clauseChain` | a `FetchChainableBuilderType` built from a chain of clauses

  #### Return Value

  the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchChainableBuilderType`, or `nil` if no match was found

- `fetchObjectIDs(_:_:)`

  Fetches the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.

  Throws

  `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store’s schema.

  #### Declaration

  Swift

      public func fetchObjectIDs<O>(_ from: From<O>, _ fetchClauses: FetchClause...) throws -> [NSManagedObjectID] where O : DynamicObject

  #### Parameters

  `from` | a `From` clause indicating the entity type
  `fetchClauses` | a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.

  #### Return Value

  the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s, or an empty array if no match was found

- `fetchObjectIDs(_:_:)`

  Fetches the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.

  Throws

  `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store’s schema.

  #### Declaration

  Swift

      public func fetchObjectIDs<O>(_ from: From<O>, _ fetchClauses: [FetchClause]) throws -> [NSManagedObjectID] where O : DynamicObject

  #### Parameters

  `from` | a `From` clause indicating the entity type
  `fetchClauses` | a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.

  #### Return Value

  the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s, or an empty array if no match was found

- `fetchObjectIDs(_:)`

  Fetches the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchChainableBuilderType` built from a chain of clauses.

      let idsOfAdults = transaction.fetchObjectIDs(
          From<MyPersonEntity>()
              .where(\.age > 18)
              .orderBy(.ascending(\.age))
      )

  Throws

  `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store’s schema.

  #### Declaration

  Swift

      public func fetchObjectIDs<B>(_ clauseChain: B) throws -> [NSManagedObjectID] where B : FetchChainableBuilderType

  #### Parameters

  `clauseChain` | a `FetchChainableBuilderType` built from a chain of clauses

  #### Return Value

  the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchChainableBuilderType`, or an empty array if no match was found

### QueryableSource

- `queryValue(_:_:_:)`

  Queries aggregate values as specified by the `QueryClause`s. Requires at least a `Select` clause, and optional `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.

  A “query” differs from a “fetch” in that it only retrieves values already stored in the persistent store. As such, values from unsaved transactions or contexts will not be incorporated in the query result.

  Throws

  `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store’s schema.

  #### Declaration

  Swift

      public func queryValue<O, U>(_ from: From<O>, _ selectClause: Select<O, U>, _ queryClauses: QueryClause...) throws -> U? where O : DynamicObject, U : QueryableAttributeType

  #### Parameters

  `from` | a `From` clause indicating the entity type
  `selectClause` | a `Select<U>` clause indicating the properties to fetch, and with the generic type indicating the return type.
  `queryClauses` | a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.

  #### Return Value

  the result of the the query, or `nil` if no match was found. The type of the return value is specified by the generic type of the `Select<U>` parameter.

- `queryValue(_:_:_:)`

  Queries aggregate values or aggregates as specified by the `QueryClause`s. Requires at least a `Select` clause, and optional `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.

  A “query” differs from a “fetch” in that it only retrieves values already stored in the persistent store. As such, values from unsaved transactions or contexts will not be incorporated in the query result.

  Throws

  `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store’s schema.

  #### Declaration

  Swift

      public func queryValue<O, U>(_ from: From<O>, _ selectClause: Select<O, U>, _ queryClauses: [QueryClause]) throws -> U? where O : DynamicObject, U : QueryableAttributeType

  #### Parameters

  `from` | a `From` clause indicating the entity type
  `selectClause` | a `Select<U>` clause indicating the properties to fetch, and with the generic type indicating the return type.
  `queryClauses` | a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.

  #### Return Value

  the result of the the query, or `nil` if no match was found. The type of the return value is specified by the generic type of the `Select<U>` parameter.

- `queryValue(_:)`

  Queries a property value or aggregate as specified by the `QueryChainableBuilderType` built from a chain of clauses.

  A “query” differs from a “fetch” in that it only retrieves values already stored in the persistent store. As such, values from unsaved transactions or contexts will not be incorporated in the query result.

      let averageAdultAge = transaction.queryValue(
          From<MyPersonEntity>()
              .select(Int.self, .average(\.age))
              .where(\.age > 18)
      )

  Throws

  `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store’s schema.

  #### Declaration

  Swift

      public func queryValue<B>(_ clauseChain: B) throws -> B.ResultType? where B : QueryChainableBuilderType, B.ResultType : QueryableAttributeType

  #### Parameters

  `clauseChain` | a `QueryChainableBuilderType` indicating the property/aggregate to fetch and the series of queries for the request.

  #### Return Value

  the result of the the query as specified by the `QueryChainableBuilderType`, or `nil` if no match was found.

- `queryAttributes(_:_:_:)`

  Queries a dictionary of attribute values as specified by the `QueryClause`s. Requires at least a `Select` clause, and optional `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.

  A “query” differs from a “fetch” in that it only retrieves values already stored in the persistent store. As such, values from unsaved transactions or contexts will not be incorporated in the query result.

  Throws

  `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store’s schema.

  #### Declaration

  Swift

      public func queryAttributes<O>(_ from: From<O>, _ selectClause: Select<O, NSDictionary>, _ queryClauses: QueryClause...) throws -> [[String : Any]] where O : DynamicObject

  #### Parameters

  `from` | a `From` clause indicating the entity type
  `selectClause` | a `Select<U>` clause indicating the properties to fetch, and with the generic type indicating the return type.
  `queryClauses` | a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.

  #### Return Value

  the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.

- `queryAttributes(_:_:_:)`

  Queries a dictionary of attribute values as specified by the `QueryClause`s. Requires at least a `Select` clause, and optional `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.

  A “query” differs from a “fetch” in that it only retrieves values already stored in the persistent store. As such, values from unsaved transactions or contexts will not be incorporated in the query result.

  Throws

  `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store’s schema.

  #### Declaration

  Swift

      public func queryAttributes<O>(_ from: From<O>, _ selectClause: Select<O, NSDictionary>, _ queryClauses: [QueryClause]) throws -> [[String : Any]] where O : DynamicObject

  #### Parameters

  `from` | a `From` clause indicating the entity type
  `selectClause` | a `Select<U>` clause indicating the properties to fetch, and with the generic type indicating the return type.
  `queryClauses` | a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.

  #### Return Value

  the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.

- `queryAttributes(_:)`

  Queries a dictionary of attribute values or as specified by the `QueryChainableBuilderType` built from a chain of clauses.

  A “query” differs from a “fetch” in that it only retrieves values already stored in the persistent store. As such, values from unsaved transactions or contexts will not be incorporated in the query result.

      let results = dataStack.queryAttributes(
          From<MyPersonEntity>()
              .select(
                  NSDictionary.self,
                  .attribute(\.age, as: "age"),
                  .count(\.age, as: "numberOfPeople")
               )
              .groupBy(\.age)
      )
      for dictionary in results! {
          let age = dictionary["age"] as! Int
          let count = dictionary["numberOfPeople"] as! Int
          print("There are \(count) people who are \(age) years old."
      }

  Throws

  `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store’s schema.

  #### Declaration

  Swift

      public func queryAttributes<B>(_ clauseChain: B) throws -> [[String : Any]] where B : QueryChainableBuilderType, B.ResultType == NSDictionary

  #### Parameters

  `clauseChain` | a `QueryChainableBuilderType` indicating the properties to fetch and the series of queries for the request.

  #### Return Value

  the result of the the query as specified by the `QueryChainableBuilderType`

### FetchableSource, QueryableSource

- `unsafeContext()`

  The internal `NSManagedObjectContext` managed by this instance. Using this context directly should typically be avoided, and is provided by CoreStore only for extremely specialized cases.

  #### Declaration

  Swift

      public func unsafeContext() -> NSManagedObjectContext