PostgresTriggerGenerator

Classes > Sync.Postgres > PostgresTriggerGenerator

Generates sync triggers for PostgreSQL tables. Implements spec Section 9 (LQL Trigger Generation) for PostgreSQL dialect.

public static class PostgresTriggerGenerator

Methods

GenerateTriggers(string, IReadOnlyList<string>, string)

public static string GenerateTriggers(string tableName, IReadOnlyList<string> columns, string pkColumn)

Generates sync triggers for a table. Creates INSERT, UPDATE, and DELETE triggers that log changes to _sync_log.

Parameters:

Name Type Description
tableName String Name of the table to generate triggers for.
columns String> List of column names to include in payload.
pkColumn String Primary key column name.

Returns: String - SQL DDL for all three triggers.

GenerateTriggersFromSchema(NpgsqlConnection, string, ILogger)

[SuppressMessage("Security", "CA2100:Review SQL queries for security vulnerabilities", Justification = "Information schema query is safe metadata query")]
public static Result<string, SyncError> GenerateTriggersFromSchema(NpgsqlConnection connection, string tableName, ILogger logger)

Generates triggers for a table by reading schema from database.

Parameters:

Name Type Description
connection NpgsqlConnection PostgreSQL connection.
tableName String Table to generate triggers for.
logger ILogger Logger for trigger generation.

Returns: SyncError> - Trigger SQL or database error.

CreateTriggers(NpgsqlConnection, string, ILogger)

[SuppressMessage("Security", "CA2100:Review SQL queries for security vulnerabilities", Justification = "Trigger DDL is generated from trusted schema metadata")]
public static Result<bool, SyncError> CreateTriggers(NpgsqlConnection connection, string tableName, ILogger logger)

Creates sync triggers in the database for a table.

Parameters:

Name Type Description
connection NpgsqlConnection PostgreSQL connection.
tableName String Table to create triggers for.
logger ILogger Logger for trigger creation.

Returns: SyncError> - Success or database error.

DropTriggers(NpgsqlConnection, string, ILogger)

[SuppressMessage("Security", "CA2100:Review SQL queries for security vulnerabilities", Justification = "Table name is used for DROP TRIGGER IF EXISTS which is safe")]
public static Result<bool, SyncError> DropTriggers(NpgsqlConnection connection, string tableName, ILogger logger)

Drops sync triggers for a table.

Parameters:

Name Type Description
connection NpgsqlConnection PostgreSQL connection.
tableName String Table to drop triggers for.
logger ILogger Logger for trigger operations.

Returns: SyncError> - Success or database error.

GetTableColumns(NpgsqlConnection, string)

[SuppressMessage("Security", "CA2100:Review SQL queries for security vulnerabilities", Justification = "Information schema query is safe metadata query")]
public static Result<IReadOnlyList<TriggerColumnInfo>, SyncError> GetTableColumns(NpgsqlConnection connection, string tableName)

Gets column information for a table.

Parameters:

Name Type Description
connection NpgsqlConnection PostgreSQL connection.
tableName String Table name.

Returns: SyncError> - List of columns or database error.