Skip to content

Rules

DataSync has a concept called Rule which represents an operation to perform in the replication process.

Currently, there are two types of them:

  • Export Rules: act on the export replication process.
  • Import Rules: act on the import replication process.

Modifiers

When we try to create an import or export rule, we need to have something that allow us to modify the sql statement that will be executed to import or export data. For that reason, we created the modifiers.

Modifiers are interfaces that allow us to add information to the import/export rule.

C#
/// <summary>
/// Condition used by the statement.
/// </summary>
public interface IFilterExpressionModifier
{
    /// <summary>
    /// Gets the filter expression.
    /// </summary>
    public string FilterExpression { get; }
}

Every modifier has an extension method associated that allow us to modify the statement that will be processed for the rule.

C#
1
2
3
4
5
public static void ApplyFilterExpressionModifier<T>(this IFilterExpressionModifier filterExpression, T statement)
    where T : IDBConditionsStatement<T>
{
    statement.AddCondition(filterExpression.FilterExpression);
}

Since rules implement modifier's interfaces, we can use this external actions in the rule's logic, for example:

C#
public SelectStatementParameters GetSelectionStatementParams()
{
    var statement = new SelectStatementParameters()
        .SetTableName(this.Table.TableName)
        .AddColumns(this.Table.Columns.Select(x => x.ColumnName));

    if (!this.FilterExpression.IsNullOrEmpty())
    {
        this.ApplyFilterExpressionModifier(statement);
    }

    if (!this.ColumnNames.IsNullOrEmpty())
    {
        this.ApplyColumnFilterModifier(statement);
    }

    return statement;
}

Modifiers Types

Filter Expression

Changes the statement's condition.

Stamp

Changes the values of certain columns of the rows affected by the execution of the rule.

For Example: after exporting all the rows, change their ExportMarker column's value to 1.