Documentation
¶
Overview ¶
Package watcher provides real-time, interactive database schema introspection and visualization for SQLite, PostgreSQL, and MySQL databases.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ChangesHandler ¶ added in v0.1.7
func ChangesHandler(d *Differ) http.HandlerFunc
ChangesHandler serves schema diffs.
GET → returns the latest SchemaDiff as JSON (empty diff if < 2 snapshots). POST → takes a new snapshot, then returns the resulting SchemaDiff as JSON.
func HTTPHandler ¶
func HTTPHandler(inspector Inspector) http.HandlerFunc
HTTPHandler returns an http.HandlerFunc that serves the schema watcher dashboard.
Behavior is polymorphic:
- Web browser / HTML view: Serves the interactive drag-and-drop dashboard.
- Machine / JSON view: Serves the raw schema payload when requested via the "?format=json" query parameter or an "Accept: application/json" header.
Types ¶
type ColumnMeta ¶ added in v0.1.7
type ColumnMeta = model.ColumnMeta
ColumnMeta extends raw column data with constraint information.
type Differ ¶ added in v0.1.7
type Differ struct {
// contains filtered or unexported fields
}
Differ takes schema snapshots and computes diffs between consecutive ones.
func (*Differ) Diff ¶ added in v0.1.7
func (d *Differ) Diff() (SchemaDiff, bool)
Diff returns the diff between the two most recent snapshots. Returns zero SchemaDiff and false when fewer than two snapshots exist.
type Inspector ¶
type Inspector interface {
// Tables returns a list of all user-defined table names.
Tables(ctx context.Context) ([]string, error)
// Columns returns column descriptors for a table in "name|type|pk" format.
Columns(ctx context.Context, tableName string) ([]string, error)
// Relations returns foreign-key descriptors for a table in "fromCol -> targetTable.targetCol" format.
Relations(ctx context.Context, tableName string) ([]string, error)
// Indexes returns a list of all indexes defined on a table (except primary keys).
Indexes(ctx context.Context, tableName string) ([]Index, error)
// ColumnMeta returns column descriptors with extra constraints.
ColumnMeta(ctx context.Context, tableName string) ([]ColumnMeta, error)
}
Inspector defines the contract for database schema introspection. Implementations query database metadata catalog schemas to extract table structures, columns, and foreign key relationships.
func NewInspector ¶
NewInspector automatically detects the driver type of the provided *sql.DB connection and returns the corresponding Inspector implementation.
Supported drivers are:
- SQLite: CGO "*sqlite3.SQLiteDriver" (github.com/mattn/go-sqlite3) and pure Go "*sqlite.Driver" (modernc.org/sqlite)
- PostgreSQL: "*pq.Driver" (github.com/lib/pq) and "*stdlib.Driver" (github.com/jackc/pgx)
- MySQL / MariaDB: "*mysql.MySQLDriver" (github.com/go-sql-driver/mysql)
Instrumented wrappers such as otelsql are also supported: NewInspector first attempts to unwrap the driver via the Unwrap() driver.Driver interface, and if that is not available it falls back to dialect probing (one lightweight query per candidate dialect).
Returns an error if the database driver is unsupported.
type SchemaDiff ¶ added in v0.1.7
type SchemaDiff struct {
Before time.Time `json:"before"`
After time.Time `json:"after"`
AddedTables []string `json:"addedTables"`
DroppedTables []string `json:"droppedTables"`
Modified []TableDiff `json:"modified"`
}
SchemaDiff describes what changed between two snapshots.
type SchemaSnapshot ¶ added in v0.1.7
SchemaSnapshot is a point-in-time capture of the full schema.
type TableDiff ¶ added in v0.1.7
type TableDiff struct {
Table string `json:"table"`
AddedColumns []string `json:"addedColumns"`
DroppedColumns []string `json:"droppedColumns"`
TypeChanges []TypeChange `json:"typeChanges"`
AddedIndexes []string `json:"addedIndexes"`
DroppedIndexes []string `json:"droppedIndexes"`
}
TableDiff describes changes within a single table.
type TypeChange ¶ added in v0.1.7
type TypeChange struct {
Column string `json:"column"`
Before string `json:"before"`
After string `json:"after"`
}
TypeChange records a column whose type changed between snapshots.
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
schema/mysql
Package mysql provides database schema introspection for MySQL and MariaDB databases.
|
Package mysql provides database schema introspection for MySQL and MariaDB databases. |
|
schema/postgres
Package postgres provides database schema introspection for PostgreSQL databases.
|
Package postgres provides database schema introspection for PostgreSQL databases. |
|
schema/sqlite
Package sqlite provides database schema introspection for SQLite databases.
|
Package sqlite provides database schema introspection for SQLite databases. |


