Registry / database / database-admin

database-admin

JSON →
library1.2.1jsnpmunverified

database-admin is a multi-database tool plugin designed for the OpenCode AI platform, providing direct SQL access and management capabilities. It currently supports MySQL, MariaDB, PostgreSQL, SQL Server, and SQLite databases. The plugin, currently at version 1.2.1, is released as part of the OpenCode ecosystem. A key differentiating feature is its robust write protection mechanism, which mandates explicit user consent for all data modification or schema alteration operations. This consent is recorded with user identity for audit purposes. Connections are managed externally via a configuration file or through an auto-discovery mechanism that scans common project environment files (e.g., .env, appsettings.json), rather than programmatic API calls. It focuses on providing a secure, auditable, and configuration-flexible SQL interface within the OpenCode environment.

npm install database-admin
INSTALL
IMPORT
SIG · DATABASE-ADMIN
D
database-admin
databasejavascriptv1.2.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Query Execution
db { "query": "SELECT * FROM users" }
import { query } from 'database-admin';
This plugin is invoked via OpenCode's internal DSL for SQL operations; direct JavaScript/TypeScript module imports are not applicable.
Grant Write Consent
db { "action": "consent", "grant": true }
databaseAdmin.grantConsent();
Plugin actions like granting consent are exclusively managed through the OpenCode `db` DSL within the OpenCode interface, not a programmatic API.
Discover Connections
db { "connection": "discover" }
const connections = require('database-admin').discoverConnections();
All interactions with the database-admin plugin, including connection discovery, occur via the OpenCode `db` command structure.

Demonstrates how to execute basic SQL queries using the `db` command within the OpenCode environment, showing auto-discovery, named connections, and direct URL usage.

db { "query": "SELECT * FROM users LIMIT 5" } -- Example with a specific connection defined in ~/.config/opencode/db-connections.json db { "query": "SELECT * FROM products", "connection": "production_db" } -- Example with a direct connection URL (use environment variables for credentials) db { "query": "SELECT 1", "connection": "mysql://root:${process.env.DB_PASSWORD ?? ''}@localhost:3306/mydb" }
Debug
Known issues
breakingAll write operations (INSERT, UPDATE, DELETE, DROP, etc.) are strictly protected and require explicit user consent via `db { "action": "consent", "grant": true }` before execution. This is a mandatory safety feature and will block operations without prior consent.
fix
Execute `db { "action": "consent", "grant": true }` to enable write operations. Consider using `scope: "session"` for temporary consent or `scope: "global"` for permanent access during your workflow.
affects: >=1.0.0
gotchaGranting write consent results in the logging of user identity (name, email, hostname) for audit purposes. Users should be aware of this data recording policy.
fix
Be mindful of the audit logging before granting consent. For sensitive operations, consider using a more restrictive consent scope like `"operation"` or `"session"` to limit exposure.
affects: >=1.0.0
gotchaDatabase connections are primarily configured externally via `~/.config/opencode/db-connections.json` or through an auto-discovery mechanism scanning project files (.env, appsettings.json, etc.), rather than programmatic API calls within the OpenCode environment itself.
fix
Ensure connection files (e.g., `~/.config/opencode/db-connections.json`) are correctly formatted and accessible to OpenCode, or provide complete connection URLs directly within your `db` query commands.
affects: >=1.0.0
Errors
Common errors & fixes
Write operation denied: Consent not granted.
An attempt was made to execute a DML (e.g., INSERT, UPDATE, DELETE) or DDL (e.g., CREATE, ALTER, DROP) operation without first explicitly granting write consent.
fix
Grant consent for write operations by executing `db { "action": "consent", "grant": true }` within the OpenCode interface. You can specify a `scope` (e.g., `"session"`, `"global"`) for the consent duration.
Database connection 'my_connection_name' not found.
The connection name specified in the `connection` field of the `db` command does not exist in your `~/.config/opencode/db-connections.json` file, or the direct connection URL is malformed.
fix
Verify that `my_connection_name` is correctly defined in `~/.config/opencode/db-connections.json`, or provide a valid, complete connection URL directly in the `connection` field of your query.
Plugin 'database-admin' not enabled or found.
The `database-admin` plugin is not correctly listed in the `plugins` array of your OpenCode configuration.
fix
Ensure that `"database-admin"` is included in the `plugins` array within your OpenCode configuration file (e.g., `~/.config/opencode/config.json`).
Upgrade
Version history
1.2.1latest on npm
Audit
Dependencies
@opencode-ai/pluginrequiredPeer dependency as it is an OpenCode plugin.
Agent activity
11 hits · last 30 days
node
10
Resources
database-admin — npm install database-admin · libregistry