Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
66 lines (48 sloc) 1.54 KB
description
The triggers are a good way to execute an action when a Type-DB method is called.

Triggers

How to Use ?

Method to use in the fluent configuration builder: .UseTriggers()

Basic Example

This simple example show the usage of Triggers.

{% code-tabs %} {% code-tabs-item title="triggers-example.cs" %}

using (var tdb = new TypeDB.Core(Mode.Standalone)

    .UseTriggers(new Trigger(MethodType.Set, (dto) =>
    {
        Console.WriteLine($"Hey you have set the '{dto.Key}' entity !");
        // Hey you have set the 'hello' entity !
    }))
    .Connect())
using (var testdb = tdb.OpenDatabase("test", true))
{
    testdb.Set<string>("hello", "world");
}

{% endcode-tabs-item %} {% endcode-tabs %}

About Callback and DTO

When you create a trigger when new Trigger() you need to give a callback as the second parameter, this callback return a DTO object that contain the collection, the key and the value that is concerned.

If you want to use DTO object in a non-anonymous function you need to add this reference:

using TypeDB.Interception;

Methods that you can Trigger

You can place a Trigger on all of this methods:

  • MethodType.Set
  • MethodType.Get
  • MethodType.Increment
  • MethodType.Decrement
  • MethodType.Lock
  • MethodType.Unlock
  • MethodType.Expire
  • MethodType.Exist
  • MethodType.Filter
  • MethodType.Drop
  • MethodType.Clear

Triggers in the Future

We have intention to add more triggering capabilities other than just methods execution.

You can’t perform that action at this time.