{"id":17562,"library":"database-admin","title":"Database Admin for OpenCode","description":"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.","status":"active","version":"1.2.1","language":"javascript","source_language":"en","source_url":"https://github.com/nyingimaina/open-code-database-admin","tags":["javascript","opencode","opencode-plugin","mysql","mariadb","postgresql","postgres","sqlserver","sqlite","typescript"],"install":[{"cmd":"npm install database-admin","lang":"bash","label":"npm"},{"cmd":"yarn add database-admin","lang":"bash","label":"yarn"},{"cmd":"pnpm add database-admin","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency as it is an OpenCode plugin.","package":"@opencode-ai/plugin","optional":false}],"imports":[{"note":"This plugin is invoked via OpenCode's internal DSL for SQL operations; direct JavaScript/TypeScript module imports are not applicable.","wrong":"import { query } from 'database-admin';","symbol":"Query Execution","correct":"db { \"query\": \"SELECT * FROM users\" }"},{"note":"Plugin actions like granting consent are exclusively managed through the OpenCode `db` DSL within the OpenCode interface, not a programmatic API.","wrong":"databaseAdmin.grantConsent();","symbol":"Grant Write Consent","correct":"db { \"action\": \"consent\", \"grant\": true }"},{"note":"All interactions with the database-admin plugin, including connection discovery, occur via the OpenCode `db` command structure.","wrong":"const connections = require('database-admin').discoverConnections();","symbol":"Discover Connections","correct":"db { \"connection\": \"discover\" }"}],"quickstart":{"code":"db { \"query\": \"SELECT * FROM users LIMIT 5\" }\n\n-- Example with a specific connection defined in ~/.config/opencode/db-connections.json\ndb { \"query\": \"SELECT * FROM products\", \"connection\": \"production_db\" }\n\n-- Example with a direct connection URL (use environment variables for credentials)\ndb { \"query\": \"SELECT 1\", \"connection\": \"mysql://root:${process.env.DB_PASSWORD ?? ''}@localhost:3306/mydb\" }","lang":"javascript","description":"Demonstrates how to execute basic SQL queries using the `db` command within the OpenCode environment, showing auto-discovery, named connections, and direct URL usage."},"warnings":[{"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.","message":"All 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.","severity":"breaking","affected_versions":">=1.0.0"},{"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.","message":"Granting write consent results in the logging of user identity (name, email, hostname) for audit purposes. Users should be aware of this data recording policy.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"Database 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.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-23T00:00:00.000Z","next_check":"2026-07-22T00:00:00.000Z","problems":[{"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.","cause":"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.","error":"Write operation denied: Consent not granted."},{"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.","cause":"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.","error":"Database connection 'my_connection_name' not found."},{"fix":"Ensure that `\"database-admin\"` is included in the `plugins` array within your OpenCode configuration file (e.g., `~/.config/opencode/config.json`).","cause":"The `database-admin` plugin is not correctly listed in the `plugins` array of your OpenCode configuration.","error":"Plugin 'database-admin' not enabled or found."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}