# Other Operations

# Size of a Repository

You can get the size of a repository using size getter. It returns a future of the number of entities in the repository.

int size = await productRepository.size;

# Clearing a Repository

You can clear all the entities from a repository using clear() method. It removes all the entities from the repository and index entries from the indexes. It does not drop the repository.

await productRepository.clear();

# Dropping a Repository

You can drop a repository using drop() method. It removes all the entities from the repository and index entries from the indexes. It also drops all the indexes associated with the repository. It also removes the repository from the database.

await productRepository.drop();

You can call isDropped getter to check if the repository is dropped or not.

bool isDropped = productRepository.isDropped;

# Closing a Repository

You can close a repository using close() method. Any further operation on a closed repository will throw NitriteIOException.

await productRepository.close();

After closing a repository, you must re-open it via Nitrite.getRepository() method to perform any operation on it.

You can call isOpen getter to check if the repository is closed or not.

bool isOpen = productRepository.isOpen;

# Event Listener

You can register an event listener on a repository to get notified on entity changes. The event listener is a function of type CollectionEventListener. It will receive CollectionEventInfo whenever an entity is inserted, updated or removed from the repository.

productRepository.subscribe((eventInfo) {
  // do something with eventInfo

You can unsubscribe the event listener using unsubscribe() method.


# CollectionEventInfo

More on CollectionEventInfo can be found here.

# Attributes

Attributes is a metadata information associated with a repository.

You can get/set attributes on a repository. The attributes are stored in the database and can be retrieved later. The attributes are stored in a special map named $nitrite_meta_map.

// get the attributes
var attributes = await productRepository.getAttributes();
attributes.set('key', 'value');

// save the attributes
await productRepository.setAttributes(attributes);

// get the attributes
attributes = await productRepository.getAttributes();

// get the value of a key
var value = attributes.get['key'];

# Processors

Processor can be used to process the underlying documents of a repository. More on processors can be found here.

# Registering a Processor

You can register a processor on a repository using addProcessor() method. It takes a Processor as input parameter.

// create a processor
var processor = MyProcessor();

// process existing entities
await processor.process(productRepository);

// register the processor

# Available Processors

Nitrite provides a StringFieldEncryptionProcessor which can be used to encrypt a field before writing it into a repository and decrypt a field after reading it from a repository.

More on this is described in Support.