saropa_drift_advisor library
Debug-only HTTP server that exposes SQLite/Drift table data as JSON and a minimal web viewer.
Architecture: The package is
dependency-injection friendly: it does not depend
on drift. You supply a DriftDebugQuery that
runs SQL; the server uses it for table listing,
table data, schema, and optional read-only SQL
runner. One server per process;
DriftDebugServer.stop clears state so
DriftDebugServer.start can be called again
(e.g. in tests).
Use from any Flutter or Dart app that has a SQLite (or Drift) database. Add the package (from pub.dev or a path dependency), then start the server with DriftDebugServer.start, passing a DriftDebugQuery callback that runs SQL and returns rows as maps.
Public API
- DriftDebugServer — Static API: DriftDebugServer.start to run the server, DriftDebugServer.stop to shut it down, DriftDebugServer.port to read the bound port.
- DriftDebugQuery — Callback that executes
a SQL string and returns rows as
List<Map<String, dynamic>>. Pass as thequeryargument to DriftDebugServer.start. - DriftDebugOnLog — Optional callback for
log messages (e.g. startup banner). Pass as
onLogto DriftDebugServer.start. - DriftDebugOnError — Optional callback for
errors and stack traces. Pass as
onErrorto DriftDebugServer.start. - DriftDebugGetDatabaseBytes — Optional
callback that returns the raw SQLite file bytes.
Pass as
getDatabaseBytesto enable "Download database" in the UI. - DriftDebugErrorLogger — Helpers for DriftDebugOnLog and DriftDebugOnError: DriftDebugErrorLogger.logCallback, DriftDebugErrorLogger.errorCallback, and DriftDebugErrorLogger.callbacks for a single prefix.
See the package README for HTTP endpoints, UI features, and optional auth for dev tunnels.
Classes
- DriftDebugErrorLogger
- Best-practice error and message logger for the Drift debug server.
Mixins
- DriftDebugServer
- Debug-only HTTP server (stub when dart:io unavailable).
Extensions
- StartDriftViewerExtension on Object
-
Convenience API for Drift apps:
await myDb.startDriftViewer(...).
Typedefs
-
DriftDebugGetDatabaseBytes
= Future<
List< Function()int> > - Optional callback that returns the raw SQLite database file bytes.
- DriftDebugLoggerCallbacks = ({_ErrorCallback error, _LogCallback log})
- Type for the pair of log and error callbacks returned by DriftDebugErrorLogger.callbacks.
- DriftDebugOnError = void Function(Object error, StackTrace stack)
- Optional callback for errors (and optional stack trace).
- DriftDebugOnLog = void Function(String message)
- Optional callback for log messages.
-
DriftDebugQuery
= Future<
List< Function(String sql)Map< >String, dynamic> > - Callback that runs a single SQL query and returns rows as list of maps.
-
DriftDebugWriteQuery
= Future<
void> Function(String sql) - Optional callback for write queries (INSERT/UPDATE/DELETE). Debug-only: used exclusively by the import endpoint.