Plugin SDK
Beekeeper Studio provides two open source packages for building plugins:
| Package | What it does | Links |
|---|---|---|
Beekeeper Studio Plugin SDK (@beekeeperstudio/plugin) |
TypeScript SDK your plugin uses to talk to Beekeeper Studio | GitHub · npm · SDK Reference |
Vite build plugin (@beekeeperstudio/vite-plugin) |
Hot reloading during development and production builds for Beekeeper Studio | GitHub · npm |
Both packages are MIT licensed.
Beekeeper Studio Plugin SDK
Plugins run in a sandboxed <iframe> and talk to Beekeeper Studio with postMessage. The SDK wraps those messages in typed, promise-based functions, so you don't have to handle the message protocol yourself.
Installation
npm install @beekeeperstudio/plugin
yarn add @beekeeperstudio/plugin
Usage
// Forwards keyboard and mouse events to Beekeeper Studio
import "@beekeeperstudio/plugin/dist/eventForwarder";
import { getTables, runQuery } from "@beekeeperstudio/plugin";
// Get all tables in the current database
const tables = await getTables();
// Run a SQL query
const result = await runQuery("SELECT * FROM users LIMIT 10");
Features
- Database metadata: list schemas, tables, columns, primary keys, foreign keys and indexes with
getSchemas,getTables,getColumnsand related functions. - Queries: run SQL against the active connection with
runQuery, and show results in Beekeeper Studio's result table withexpandTableResult. - Connection and app info: read connection details, the app version and theme, and update status with
getConnectionInfo,getAppInfoandcheckForUpdate. - Views and tabs: read how a view was opened with
getViewContext, keep per-view state withgetViewStateandsetViewState, set the tab title, open query and table tabs withopenTab, and control the status bar. - Storage: save plugin data, optionally encrypted, with
appStorage. - App UI: show toast notifications with
notyand confirmation dialogs withconfirm. - System integration: read and write the clipboard, open native save dialogs with
requestFileSaveand open links in the browser withopenExternal. - Events: react to theme changes, table changes and window events, and send messages between your plugin's views with
broadcast. - Keyboard and mouse forwarding: importing
@beekeeperstudio/plugin/dist/eventForwarderpasses app shortcuts and pointer events from your plugin through to Beekeeper Studio. - Debugging: log every message with
setDebugCommsand write to the app log withlog.error. - TypeScript types: typed requests and responses, plus shared models such as
Table,QueryResultand the context menu params.
The SDK Reference documents every function, event and type.
Vite Build Plugin
@beekeeperstudio/vite-plugin is the recommended way to build a plugin with Vite. It:
- Enables hot module replacement inside Beekeeper Studio during development
- Rewrites your HTML for production builds so bundled assets load correctly in the app
You still use the SDK in your plugin code; the build plugin only changes how it is built and served.
Installation
npm install --save-dev @beekeeperstudio/vite-plugin
yarn add -D @beekeeperstudio/vite-plugin
Configuration
Add it to vite.config.ts:
import { defineConfig } from "vite";
import bks from "@beekeeperstudio/vite-plugin";
export default defineConfig({
plugins: [bks()],
});
By default it transforms index.html into dist/index.html, which matches a view entry of dist/index.html in your manifest. If your plugin has more than one HTML page, list each one with the entrypoints option:
export default defineConfig({
plugins: [
bks({
entrypoints: [
{ input: "index.html", output: "dist/index.html" },
{ input: "config.html", output: "dist/config.html" },
],
}),
],
});
Next Steps
- Creating Your First Plugin: build a plugin with the SDK and the Vite build plugin
- SDK Reference: every function, event and type in the SDK
- Manifest Reference: describe your plugin's views and menus