Lantern.Explorer (Lantern v0.6.0)

Copy Markdown View Source

An embeddable Postgres table browser & editor LiveComponent.

Drop it into any LiveView and hand it a connection source — Lantern manages the rest (table picker, grid, filtering, sorting, pagination, inline editing, row insertion, and bulk delete).

<.live_component
  module={Lantern.Explorer}
  id="lantern"
  source={"postgres://user:pass@host:5432/db"}
/>

:source is anything Lantern.Source.from/1 accepts. The component owns all of its state and runs each query synchronously over a short-lived connection, so the host LiveView has nothing to supervise.

Options

Pass these attributes when mounting:

  • :source — required. See Lantern.Source.
  • :title — heading text. Default "Data".
  • :class — extra class/classes for the root .lantern element.
  • :theme:system/"system" (default), :light/"light", or :dark/"dark"; rendered as data-theme for CSS targeting.
  • :style — inline root style, useful for setting --lt-* CSS variables.
  • :allow_raw_filter — when true, exposes a raw SQL filter input that is appended after WHERE. Default false. Enable only for trusted operators: a user-supplied fragment can execute arbitrary SQL (data- modifying CTEs, sub-selects, etc.) under the connection role's privileges. Lantern explicitly never sees the filter as parameterizable input — it's a literal SQL fragment.
  • :allow_sql_workspace — when true, exposes a SQL workspace. Default false.
  • :sql_mode:trusted (default when SQL workspace is enabled) or :read_only.
  • :read_only — when true, the explorer is browse-only: inline editing, row insertion, bulk delete, and all DDL are hidden in the UI and refused server-side, and the SQL workspace accepts SELECT/EXPLAIN only. Default false. Useful for public or untrusted-viewer deployments.

Styling

Dependency-free: a plain Phoenix.LiveComponent with inlined Heroicons (MIT) and semantic lt-* class names — no Fluxon or icon library required. All markup lives under a .lantern root and every class is a single-class selector, so integrators override freely.

Import the bundled lantern.css for good-looking defaults out of the box; it is driven entirely by --lt-* CSS variables, so re-theming means overriding a handful of variables (no Tailwind needed). Column resizing, the "set NULL" button, and live JSON validation need the LanternGrid JS hook registered in your LiveSocket — see the README for setup.

Editing notes: rows are edited/deleted by primary key, so a table without one is insert-only — you can still add rows, but existing rows can't be edited or deleted. An empty input is written as SQL NULL.