ManagedContext class

A service object that handles connecting to and sending queries to a database.

You create objects of this type to use the Conduit ORM. Create instances in ApplicationChannel.prepare and inject them into controllers that execute database queries.

A context contains two types of objects:

  • PersistentStore : Maintains a connection to a specific database. Transfers data between your application and the database.
  • ManagedDataModel : Contains information about the ManagedObject subclasses in your application.

Example usage:

    class Channel extends ApplicationChannel {
       ManagedContext context;

       @override
       Future prepare() async {
          var store = new PostgreSQLPersistentStore(...);
          var dataModel = new ManagedDataModel.fromCurrentMirrorSystem();
          context = new ManagedContext(dataModel, store);
       }

       @override
       Controller get entryPoint {
         final router = new Router();
         router.route("/path").link(() => new DBController(context));
         return router;
       }
    }

Constructors

ManagedContext(ManagedDataModel? dataModel, PersistentStore persistentStore)
Creates an instance of ManagedContext from a ManagedDataModel and PersistentStore.
ManagedContext.childOf(ManagedContext parentContext)
Creates a child context from parentContext.

Properties

dataModel → ManagedDataModel?
The data model containing the ManagedEntitys that describe the ManagedObjects this instance works with.
final
hashCode → int
The hash code for this object.
no setterinherited
persistentStore ↔ PersistentStore
The persistent store that Querys on this context are executed through.
getter/setter pair
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

close() → Future
Closes this context and release its underlying resources.
documentComponents(APIDocumentContext context) → void
Tells this object to add its components to context.
entityForType(Type type) → ManagedEntity
Returns an entity for a type from dataModel.
fetchObjectWithID<T extends ManagedObject>(dynamic identifier) → Future<T?>
Returns an object of type T from this context if it exists, otherwise returns null.
insertObject<T extends ManagedObject>(T object) → Future<T>
Inserts a single object into this context.
insertObjects<T extends ManagedObject>(List<T> objects) → Future<List<T>>
Inserts each object in objects into this context.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited
transaction<T>(Future<T> transactionBlock(ManagedContext transaction)) → Future<T>
Runs all Querys in transactionBlock within a database transaction.

Operators

operator ==(Object other) → bool
The equality operator.
inherited