Triggers

Tabularis manages triggers as a first-class database object across all three built-in drivers — listing, viewing definitions, creating, editing, and dropping — with sidebar integration and a guided editor modal.

Browsing Triggers

Triggers accordion in the Tabularis Explorer sidebar with timing and event badges next to a read-only View Definition tab

A Triggers accordion appears under every schema (PostgreSQL), database (MySQL multi-db), and in the flat layout for MySQL single-db / SQLite. Each entry shows:

Field Description
Name The trigger name
Timing / Event badge e.g. BEFORE INSERT, AFTER UPDATE, INSTEAD OF DELETE. Multi-event triggers (e.g. BEFORE INSERT OR UPDATE) are aggregated into a single entry.
Table tooltip Hovering shows the trigger's target table.

A filter field at the top of the accordion matches the existing table-filter pattern — start typing to narrow the list.

Viewing the Definition

Double-click a trigger — or right-click → View Definition — to open the trigger SQL in a read-only editor tab. The Run and Explain Plan buttons are hidden on definition tabs, since you're inspecting DDL rather than running a query.

The definition is fetched directly from the database catalog:

  • PostgreSQL — pg_get_triggerdef
  • MySQL / MariaDB — SHOW CREATE TRIGGER
  • SQLite — the original sql column in sqlite_master

Creating a Trigger

Create Trigger modal in Guided mode with name and table fields, BEFORE / AFTER / INSTEAD OF timing pills, INSERT / UPDATE / DELETE event buttons, a Monaco body editor, and a generated SQL preview

Click the + button on the Triggers accordion header (tooltip Create New Trigger). The trigger editor opens in Guided mode with:

Field Description
Name Identifier; quoting follows the driver.
Table Name The target table, typed in by hand.
Timing Since v0.28.0 only the timings the driver supports: BEFORE / AFTER / INSTEAD OF on PostgreSQL and SQLite, BEFORE / AFTER on MySQL / MariaDB.
Events INSERT, UPDATE, DELETE. On PostgreSQL several can be selected and are joined with OR; since v0.28.0 MySQL / MariaDB and SQLite allow one event per trigger, with the hint "This database allows one event per trigger."
Body The action body, edited in Monaco.
SQL Preview Live preview of the CREATE TRIGGER statement that will be executed.

A Raw SQL tab is always available alongside Guided mode for hand-written DDL; switching to it from Guided mode starts from the generated SQL. On PostgreSQL a trigger calls a trigger function, so since v0.28.0 Guided mode generates both: a CREATE OR REPLACE FUNCTION holding the body and a CREATE TRIGGER … EXECUTE FUNCTION that calls it. MySQL / MariaDB and SQLite keep the body inline.

Editing a Trigger

Edit Trigger modal with the existing trg_employees_au_audit_salary trigger loaded — name, table, AFTER timing, and UPDATE event pre-selected from the parsed definition, with the IF OLD.salary <> NEW.salary body in the Monaco editor and a Save Changes button

Right-click a trigger → Edit. The modal opens in Guided mode by default and parses the loaded definition to populate the fields (timing, the events, and the body after FOR EACH ROW). Since v0.28.0 every event of a multi-event trigger is loaded, not just the first. On PostgreSQL, editing keeps the trigger's existing function ("This trigger keeps its existing function. Edit the function itself in the SQL editor or raw SQL mode."). FOR EACH STATEMENT triggers are not represented in Guided mode (a WHEN clause stays inside the body text), so use the Raw SQL tab, which shows the original definition unchanged, for those. The name and table cannot be changed when editing.

Triggers are edited as drop + recreate — the database engines don't expose an ALTER TRIGGER that covers what the modal needs to change. The modal asks for confirmation (Recreate Trigger), then drops the trigger and creates the new definition as two separate steps. Since v0.28.0, if the new definition fails, Tabularis recreates the original trigger from its saved definition and reports "The original trigger was restored."; if restoring fails too, the error says so.

Dropping a Trigger

Right-click a trigger → Drop Trigger. A confirmation is shown before the DROP TRIGGER statement is executed.

Driver Support

Feature PostgreSQL MySQL / MariaDB SQLite
List triggers Yes Yes Yes
Multi-event aggregation Yes (string_agg on information_schema.triggers) n/a (single-event only at the DB level) n/a
Guided timings BEFORE, AFTER, INSTEAD OF BEFORE, AFTER BEFORE, AFTER, INSTEAD OF
View definition Yes (pg_get_triggerdef) Yes Yes (parsed from sqlite_master.sql)
Create / Edit / Drop Yes Yes Yes
Multi-database connections Schema-qualified Database-qualified; pool is switched to the correct database before CREATE TRIGGER n/a

MySQL specifics

  • All trigger DDL is executed via sqlx::raw_sql to bypass MySQL server error 1295 ("This command is not supported in the prepared statement protocol yet").
  • For multi-database connections, every trigger operation is qualified with the database name and the pool is switched to that database before CREATE TRIGGER. The ON <table> clause is emitted without a schema prefix, matching MySQL's expectation that schema is resolved from the connection.

Plugin drivers

Plugin drivers that don't implement triggers degrade gracefully: get_triggers returns an empty list rather than failing the whole schema load. The triggers capability flag in DriverCapabilities advertises whether a driver supports the feature.

Data Model

Each trigger is represented as TriggerInfo:

Field Description
name Trigger name
table_name Target table
event Aggregated event(s): INSERT, UPDATE, DELETE, TRUNCATE, or combinations.
timing BEFORE, AFTER, or INSTEAD OF
definition The raw SQL definition as returned by the catalog.

Four Tauri commands back the UI: get_triggers, get_trigger_definition, create_trigger, drop_trigger.