SqliteDebugTab

The SQLite tab: the tables, schemas, and rows of the app's SQLite and Room databases, under /api/v1/sqlite/.

Register it from debug code, as the Network tab:

Lustro.builder(app)
.addTab(
SqliteDebugTab.create(
databases = listOf(
SqliteDb.support("app") { appDatabase.openHelper.writableDatabase },
SqliteDb.file("cache", app.getDatabasePath("cache.db")),
),
),
)
.build()
.start()

The tab shows the registered databases, and, when the app passes a context as discoverFrom, the other database files in the app's databases and noBackupFilesDir directories, such as those of its libraries and WorkManager's androidx.work.workdb. It opens a discovered file read-only for each request, as a SqliteDb.file database.

The routes that browse run only the SQL that the tab builds itself: a client names a database, a table, and a column, and the tab checks each name against the database's schema before it puts it in a statement, as a quoted identifier. A filter value is a bound parameter. A page of rows holds at most 4096 characters of a text value, with its length, and only the size of a blob, so a large cell does not fill the memory or the response. Each read stops when the request times out.

POST query runs a client's statement on a connection that SQLite opens read-only to the database's file, for one request, so SQLite refuses every write. POST exec, edit, and delete write through the app's handle, only to a writable database. Neither route runs a statement that would leave a transaction or a setting on a connection: BEGIN, SAVEPOINT, and the other transaction statements, ATTACH, DETACH, and VACUUM, and in exec also every PRAGMA.

Every client that has the token can read every registered database, and write every writable one: register only the databases that you want to show, and make writable only those that a client may change. By default, the tab leaves out the values of the columns whose names look like they hold a secret, as SqliteValuePolicy.MASK_SENSITIVE says; that keeps them off the screen, but a client's own statement can still read them. A registration can show some of those columns with unmasked; a discovered file has no such exceptions.

In the console, the tab lists the databases and their tables, and shows a page of rows, which a client sorts, filters, and pages through, with a row editor for a writable database and a console for a client's own statements. GET /api/v1/sqlite/_schema describes its routes.

Types

Link copied to clipboard
object Companion

Factory for SqliteDebugTab.

Properties

Link copied to clipboard
open override val icon: String
Link copied to clipboard
open override val id: String
Link copied to clipboard
open override val order: Int = 40
Link copied to clipboard
Link copied to clipboard
open override val title: String

Functions

Link copied to clipboard
open fun handle(request: DebugRequest): DebugResponse?
Link copied to clipboard
open fun onStart()
Link copied to clipboard
open fun onStop()
Link copied to clipboard
open override fun renderContent(): String

The view's static shell; sqlite.js and sqlite.css in the assets fill and style it.

Link copied to clipboard
open fun renderScript(): String
Link copied to clipboard
open fun renderStyles(): String
Link copied to clipboard
open fun schema(): String?