TriggerGenerator
Generates sync triggers for SQLite tables. Implements spec Section 9 (LQL Trigger Generation) for SQLite dialect.
public static class TriggerGenerator
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(SqliteConnection, string, ILogger)
[SuppressMessage("Security", "CA2100:Review SQL queries for security vulnerabilities", Justification = "PRAGMA table_info is safe metadata query")]
public static Result<string, SyncError> GenerateTriggersFromSchema(SqliteConnection connection, string tableName, ILogger logger)
Generates triggers for a table by reading schema from database.
Parameters:
| Name | Type | Description |
|---|---|---|
connection |
SqliteConnection |
SQLite connection. |
tableName |
String |
Table to generate triggers for. |
logger |
ILogger |
Logger for trigger generation. |
Returns: SyncError> - Trigger SQL or database error.
CreateTriggers(SqliteConnection, 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(SqliteConnection connection, string tableName, ILogger logger)
Creates sync triggers in the database for a table.
Parameters:
| Name | Type | Description |
|---|---|---|
connection |
SqliteConnection |
SQLite connection. |
tableName |
String |
Table to create triggers for. |
logger |
ILogger |
Logger for trigger creation. |
Returns: SyncError> - Success or database error.
DropTriggers(SqliteConnection, 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(SqliteConnection connection, string tableName, ILogger logger)
Drops sync triggers for a table.
Parameters:
| Name | Type | Description |
|---|---|---|
connection |
SqliteConnection |
SQLite connection. |
tableName |
String |
Table to drop triggers for. |
logger |
ILogger |
Logger for trigger operations. |
Returns: SyncError> - Success or database error.
GetTableColumns(SqliteConnection, string)
[SuppressMessage("Security", "CA2100:Review SQL queries for security vulnerabilities", Justification = "PRAGMA table_info is safe metadata query")]
public static Result<IReadOnlyList<TriggerColumnInfo>, SyncError> GetTableColumns(SqliteConnection connection, string tableName)
Gets column information for a table.
Parameters:
| Name | Type | Description |
|---|---|---|
connection |
SqliteConnection |
SQLite connection. |
tableName |
String |
Table name. |
Returns: SyncError> - List of columns or database error.