xray_drift_inspector
Browse, query and edit a drift database in the Database tab of the xRay inspector.
For full documentation and guides, see the xRay docs.
Disclaimer: This is a commercial package. To use this package, you need to have either a commercial xRay license or a free xRay Community License. The xRay desktop apps for macOS, Windows and Linux are the authorized UI clients for this library. For more details, please check the LICENSE file.
Setup
Pass the database your app already opened:
final database = AppDatabase();
XRayInspectorServerConfig(inspectors: [
XRayDriftInspector(database: database),
]);
The Database tab lists the tables and views with their row counts, pages through rows, and runs SQL in its Query view. It is titled with the database's class name; pass title: to name it yourself, and id: when two databases share a title.
Allowing edits
Browsing and read-only queries (SELECT, WITH … SELECT, EXPLAIN) are all the inspector allows by default. Turn on adding, editing and deleting rows, and queries that change data, with allowWrites:
XRayDriftInspector(database: database, allowWrites: true)
A row is addressed by its primary key, or by rowid in a table without one. Views, and WITHOUT ROWID tables without a primary key, stay read-only.
One connection, the app's own
xRay never opens the database file a second time. Its statements run through your GeneratedDatabase (customSelect and customUpdate), so they queue with the app's own and wait while the app holds a transaction.
Your watch() streams re-run after every edit from xRay: a row edit tells drift which table changed, and a query that changes data tells it every table changed, because xRay does not work out which tables a statement touches.
Encrypted databases
A drift database on SQLCipher (sqlcipher_flutter_libs, PRAGMA key in setup) works as is: xRay reads through the connection your app already unlocked and never needs the key.