# Context interfaces

### StoreContext

`StoreContext` is a type  indicating that the mappings context is aware of the `store` property of type `DatabaseManager` . `DatabaseManager` is a wrapper interface incapsulating the persistence layer:

```typescript
export interface StoreContext {
  store: DatabaseManager
}

/**
 * Database access interface. Use typeorm transactional entity manager to perform get/save/remove operations.
 */
export default interface DatabaseManager {
  /**
   * Save given entity instance, if entity is exists then just update
   * @param entity
   */
  save<T>(entity: DeepPartial<T>): Promise<void>;

  /**
   * Removes a given entity from the database.
   * @param entity: DeepPartial<T>
   */
  remove<T>(entity: DeepPartial<T>): Promise<void>;

  /**
   * Finds first entity that matches given options.
   * @param entity: T
   * @param options: FindOneOptions<T>
   */
  get<T>(entity: { new (...args: any[]): T }, options: FindOneOptions<T>): Promise<T | undefined>;

  /**
   * Finds entities that match given options.
   * @param entity: T
   * @param options: FindOneOptions<T>
   */
  getMany<T>(entity: { new (...args: any[]): T }, options: FindOneOptions<T>): Promise<T[]>;
}
```

### BlockContext

Contains information about the block: timestamp, height, hash, as well as the list of all events and extrinsics.

```typescript
export interface BlockContext {
  block: SubstrateBlock
}
```

### EventContext

Contains info about the event being handled and the extrinsic emitted the event. Since some events are emitted without an extrinsic (system event), the `extrinsic` parameter is optional.

```typescript
export interface EventContext extends BlockContext {
  event: SubstrateEvent
  extrinsic?: SubstrateExtrinsic
}
```

### ExtrinsicContext

Passed to extrinsic handlers. Similar to `EventContext` but `extrinsic` is now a mandatory property.

```typescript
export interface ExtrinsicContext extends BlockContext {
  event: SubstrateEvent
  extrinsic: SubstrateExtrinsic
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dzhelezov.gitbook.io/hydra/docs/mappings/databasemanager.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
