docs/plugin_development/api-reference.md
!!! warning "Beta Feature" The plugin system is in beta (available in Beekeeper Studio 5.3+). We'd love your feedback!
The Beekeeper Studio Plugin API is accessible through the @beekeeperstudio/plugin package. The API provides communication between your plugin and the main application.
=== "npm"
bash npm install @beekeeperstudio/plugin
=== "yarn"
bash yarn add @beekeeperstudio/plugin
Enable debug logging to see all communication between your plugin and Beekeeper Studio. This is helpful when developing plugins to understand what messages are being sent and received.
Usage:
setDebugComms(true);
Signature:
function setDebugComms(enabled: boolean);
Log an error message to the application log.
Usage:
import { log } from "@beekeeperstudio/plugin";
log.error('An error occurred');
Signature:
function error(err: string | Error): void;
Get a list of schemas from the current database.
Usage:
import { getSchemas } from '@beekeeperstudio/plugin';
const schemas = await getSchemas();
Example Response:
["public", "information_schema", "pg_catalog"]
Signature:
async function getSchemas(): Promise<string[]>;
Get a list of tables from the current database.
Usage:
import { getTables } from '@beekeeperstudio/plugin';
// Get all tables
const tables = await getTables();
// Get tables from a specific schema
const tables = await getTables('public');
Example Response:
[
{
name: "users",
schema: "public"
},
{
name: "orders",
schema: "public"
}
]
Signature:
async function getTables(schema?: string): Promise<{
name: string;
schema?: string;
}[]>;
Get column information for a specific table.
Usage:
import { getColumns } from '@beekeeperstudio/plugin';
const columns = await getColumns('users', 'public');
Example Response:
[
{
name: "id",
type: "integer"
},
{
name: "email",
type: "varchar"
}
]
Signature:
async function getColumns(table: string, schema?: string): Promise<{
name: string;
type: string;
}[]>;
Get foreign key relationships for a specific table.
Usage:
import { getTableKeys } from '@beekeeperstudio/plugin';
const keys = await getTableKeys('orders', 'public');
Example Response:
[
{
isComposite: false,
toTable: "users",
toSchema: "public",
toColumn: "id",
fromTable: "orders",
fromSchema: "public",
fromColumn: "user_id",
constraintName: "fk_orders_user_id",
onUpdate: "CASCADE",
onDelete: "SET NULL"
}
]
Signature:
async function getTableKeys(table: string, schema?: string): Promise<TableKey[]>;
Get primary key information for a specific table.
Usage:
import { getPrimaryKeys } from '@beekeeperstudio/plugin';
const primaryKeys = await getPrimaryKeys('users', 'public');
Example Response:
[
{
columnName: "id",
position: 1
}
]
Signature:
async function getPrimaryKeys(table: string, schema?: string): Promise<PrimaryKey[]>;
Get index information for a specific table.
Usage:
import { getTableIndexes } from '@beekeeperstudio/plugin';
const indexes = await getTableIndexes('users', 'public');
Example Response:
[
{
id: "idx_users_email",
table: "users",
schema: "public",
name: "idx_users_email",
columns: [
{
name: "email",
order: "ASC"
}
],
unique: true,
primary: false
}
]
Signature:
async function getTableIndexes(table: string, schema?: string): Promise<TableIndex[]>;
Get incoming foreign key relationships (references to this table from other tables).
Usage:
import { getIncomingKeys } from '@beekeeperstudio/plugin';
const incomingKeys = await getIncomingKeys('users', 'public');
Signature:
async function getIncomingKeys(table: string, schema?: string): Promise<TableKey[]>;
Get outgoing foreign key relationships (references from this table to other tables).
Usage:
import { getOutgoingKeys } from '@beekeeperstudio/plugin';
const outgoingKeys = await getOutgoingKeys('orders', 'public');
Signature:
async function getOutgoingKeys(table: string, schema?: string): Promise<TableKey[]>;
Execute a SQL query against the current database.
!!! warning "No Query Sanitization" The query will be executed exactly as provided with no modification or sanitization. Always validate and sanitize user input before including it in queries to prevent unwanted actions.
Usage:
import { runQuery } from '@beekeeperstudio/plugin';
const result = await runQuery('SELECT * FROM users WHERE active = true LIMIT 10');
Example Response:
{
results: [
{
fields: [
{ id: "1", name: "id", dataType: "integer" },
{ id: "2", name: "email", dataType: "varchar" }
],
rows: [
{ id: 1, email: "[email protected]" },
{ id: 2, email: "[email protected]" }
]
}
]
}
Signature:
async function runQuery(query: string): Promise<{
results: QueryResult[];
error?: unknown;
}>;
Get information about the current database connection.
Usage:
import { getConnectionInfo } from '@beekeeperstudio/plugin';
const connectionInfo = await getConnectionInfo();
Example Response:
{
connectionType: "postgresql",
id: 1,
workspaceId: 123,
connectionName: "Production DB",
databaseType: "postgresql",
databaseName: "myapp_production",
defaultSchema: "public",
readOnlyMode: false
}
Signature:
async function getConnectionInfo(): Promise<{
connectionType: string;
id: number;
workspaceId: number;
connectionName: string;
databaseType: 'postgresql' | 'mysql' | 'mariadb' | 'sqlite' | 'sqlserver' | 'oracle' | 'mongodb' | 'cassandra' | 'clickhouse' | 'firebird' | 'bigquery' | 'redshift' | 'duckdb' | 'libsql' | 'redis' | 'surrealdb' | 'trino';
databaseName: string;
defaultSchema?: string;
readOnlyMode: boolean;
}>;
Supported Connection Types:
| Value | Database |
|---|---|
postgresql | PostgreSQL |
mysql | MySQL |
mariadb | MariaDB |
sqlite | SQLite |
sqlserver | SQL Server |
oracle | Oracle Database |
mongodb | MongoDB |
cassandra | Apache Cassandra |
clickhouse | ClickHouse |
firebird | Firebird |
bigquery | Google BigQuery |
redshift | Amazon Redshift |
duckdb | DuckDB |
libsql | LibSQL |
redis | Redis |
surrealdb | SurrealDB |
trino | Trino |
Set the title of the current plugin tab.
Usage:
import { setTabTitle } from '@beekeeperstudio/plugin';
await setTabTitle('Data Analysis Tool');
Signature:
async function setTabTitle(title: string): Promise<void>;
Display query results in the bottom table panel (shell-type tabs only).
Usage:
import { expandTableResult } from '@beekeeperstudio/plugin';
await expandTableResult([{
fields: [
{ id: "1", name: 'id', dataType: 'integer' },
{ id: "2", name: 'name', dataType: 'varchar' },
],
rows: [
{ id: 1, name: 'John', age: 30 },
],
}]);
Signature:
async function expandTableResult(
results: {
fields: QueryResult[];
rows: Record<string, JsonValue>[];
}[];
): Promise<void>;
!!! tip "Table Display Tips" - Results will replace any existing table data - Datasets are not paginated. Be aware of large datasets!
Get the current view context.
A view context describes how this plugin view was opened and what data is available for it. It always includes the static command from your manifest.json, and may also include dynamic params depending on where the menu was invoked.
Usage:
import { getViewContext } from '@beekeeperstudio/plugin';
const context = await getViewContext();
Example Response:
{
command: "analyze-data",
params: {
target: {
type: "cell",
row: 0,
column: "email",
value: "[email protected]"
},
activeRange: {
rows: [0, 1, 2],
columns: ["id", "email"],
value: [
[1, "[email protected]"],
[2, "[email protected]"],
[3, "[email protected]"]
]
}
}
}
Signature:
async function getViewContext(): Promise<PluginViewContext>;
Get the current state of your view instance.
!!! tip "Learn more about View State here."
Usage:
import { getViewState } from '@beekeeperstudio/plugin';
const state = await getViewState();
Signature:
async function getViewState<T>(): Promise<T>;
Store state for your view instance.
!!! tip "Learn about more about View State here."
Usage:
import { setViewState } from '@beekeeperstudio/plugin';
await setViewState({
selectedTable: 'users',
filters: ['active = true']
});
Signature:
async function setViewState<T>(state: T): Promise<void>;
Get information about the application.
Usage:
import { getAppInfo } from '@beekeeperstudio/plugin';
const appInfo = await getAppInfo();
Signature:
async function getAppInfo(): Promise<{
version: string;
theme: {
palette: Record<string, string>;
cssString: string;
type: "dark" | "light";
};
}>;
Get the version of Beekeeper Studio.
Usage:
import { getAppVersion } from '@beekeeperstudio/plugin';
const version = await getAppVersion();
Signature:
async function getAppVersion(): Promise<string>;
Open a URL in the default external browser.
Usage:
import { openExternal } from '@beekeeperstudio/plugin';
await openExternal('https://example.com');
Signature:
async function openExternal(link: string): Promise<void>;
Retrieve stored data by key.
Usage:
import { getData } from '@beekeeperstudio/plugin';
// Get data with custom key
const data = await getData('myKey');
// Get data with default key
const data = await getData();
Signature:
async function getData<T = unknown>(key?: string): Promise<T>;
Store data that can be retrieved later.
Usage:
import { setData } from '@beekeeperstudio/plugin';
// Store with custom key
await setData('myKey', { name: 'John' });
// Store with default key
await setData({ name: 'John' });
Signature:
async function setData<T = unknown>(key: string, value: T): Promise<void>;
async function setData<T = unknown>(value: T): Promise<void>;
Retrieve encrypted stored data by key.
Usage:
import { getEncryptedData } from '@beekeeperstudio/plugin';
const secretData = await getEncryptedData('secretKey');
Signature:
async function getEncryptedData<T>(key: string): Promise<T>;
Store encrypted data that can be retrieved later.
Usage:
import { setEncryptedData } from '@beekeeperstudio/plugin';
// Store with custom key
await setEncryptedData('secretKey', { token: 'abc123' });
// Store with default key
await setEncryptedData({ token: 'abc123' });
Signature:
async function setEncryptedData<T = unknown>(key: string, value: T): Promise<void>;
async function setEncryptedData<T = unknown>(value: T): Promise<void>;
Open different types of tabs in Beekeeper Studio.
Usage:
import { openTab } from '@beekeeperstudio/plugin';
// Open a query tab
await openTab('query', { query: 'SELECT * FROM users' });
// Open a table data tab
await openTab('tableTable', {
table: 'users',
schema: 'public',
filters: [
{ field: 'active', type: '=', value: 'true' }
]
});
// Open a table structure tab
await openTab('tableStructure', {
table: 'users',
schema: 'public'
});
Signature:
async function openTab(type: "query", options?: OpenQueryTabOptions): Promise<void>;
async function openTab(type: "tableTable", options: OpenTableTableTabOptions): Promise<void>;
async function openTab(type: "tableStructure", options: OpenTableStructureTabOptions): Promise<void>;
Request a file save dialog to save data to the user's filesystem.
Usage:
import { requestFileSave } from '@beekeeperstudio/plugin';
await requestFileSave({
data: 'SELECT * FROM users',
fileName: 'query.sql',
filters: [
{ name: 'SQL Files', extensions: ['sql'] },
{ name: 'All Files', extensions: ['*'] }
]
});
// Save binary data (base64 encoded)
await requestFileSave({
data: base64ImageData,
fileName: 'chart.png',
encoding: 'base64',
filters: [
{ name: 'PNG Images', extensions: ['png'] }
]
});
Signature:
async function requestFileSave(options: RequestFileSaveOptions): Promise<void>;
Show the status bar UI for your plugin.
Usage:
import { showStatusBarUI } from '@beekeeperstudio/plugin';
await showStatusBarUI();
Signature:
async function showStatusBarUI(): Promise<void>;
Hide the status bar UI for your plugin.
Usage:
import { hideStatusBarUI } from '@beekeeperstudio/plugin';
await hideStatusBarUI();
Signature:
async function hideStatusBarUI(): Promise<void>;
Toggle the status bar UI visibility for your plugin.
Usage:
import { toggleStatusBarUI } from '@beekeeperstudio/plugin';
await toggleStatusBarUI();
Signature:
async function toggleStatusBarUI(): Promise<void>;
Write text to the system clipboard.
Usage:
import { clipboard } from '@beekeeperstudio/plugin';
await clipboard.writeText('Hello world!');
Signature:
async function writeText(text: string): Promise<void>;
Read text from the system clipboard.
Usage:
import { clipboard } from '@beekeeperstudio/plugin';
const text = await clipboard.readText();
Signature:
async function readText(): Promise<string>;
Write an image to the system clipboard.
Usage:
import { clipboard } from '@beekeeperstudio/plugin';
// data should be a base64 encoded image string
await clipboard.writeImage(base64ImageData);
Signature:
async function writeImage(data: string): Promise<void>;
Broadcast a message to other views of your plugin.
Usage:
import { broadcast } from '@beekeeperstudio/plugin';
broadcast.post("hello");
Signature:
function post(message: JsonValue): Promise<void>;
Listen for messages from other views of your plugin.
Usage:
import { broadcast } from '@beekeeperstudio/plugin';
broadcast.on((message) => {
// Handle message here
});
Signature:
function on(callback: (message: JsonValue) => void): void;
Check for updates for your plugin.
Usage:
import { checkForUpdate } from '@beekeeperstudio/plugin';
const updateAvailable = await checkForUpdate();
Signature:
async function checkForUpdate(): Promise<boolean>;
Display an informational notification toast message to the user.
Usage:
import { noty } from '@beekeeperstudio/plugin';
await noty.info('Query executed in 2.3 seconds');
Arguments Schema:
{ message: string }
Display a success notification toast message to the user.
Usage:
import { noty } from '@beekeeperstudio/plugin';
await noty.success('Data imported successfully!');
Arguments Schema:
{ message: string }
Display an error notification toast message to the user.
Usage:
import { noty } from '@beekeeperstudio/plugin';
await noty.error('Failed to connect to the database');
Arguments Schema:
{ message: string }
Display a warning notification toast message to the user.
Usage:
import { noty } from '@beekeeperstudio/plugin';
await noty.warning('This operation may take a while');
Arguments Schema:
{ message: string }
Display a confirmation dialog to the user and wait for their response.
Usage:
import { confirm } from '@beekeeperstudio/plugin';
// Basic confirmation
const result = await confirm();
if (result) {
// User clicked confirm
} else {
// User clicked cancel
}
// With title and message
const result = await confirm('Delete Table', 'Are you sure you want to delete this table?');
// With custom button labels
const result = await confirm(
'Export Data',
'This will export all data to a CSV file. Continue?',
{
confirmLabel: 'Export',
cancelLabel: 'Cancel'
}
);
Arguments Schema:
{
title?: string;
message?: string;
options?: {
confirmLabel?: string;
cancelLabel?: string;
};
}
Response Schema:
boolean // true if confirmed, false if cancelled
Notifications are events that are emitted by Beekeeper Studio to inform your plugin about changes in the application state. Use addNotificationListener to subscribe to these events and removeNotificationListener to unsubscribe.
Fired when tables in the current database have changed (e.g., after a table is created, dropped, or modified).
Usage:
import { addNotificationListener } from '@beekeeperstudio/plugin';
addNotificationListener('tablesChanged', () => {
// Refresh your table list or update UI
console.log('Tables have changed, refreshing...');
});
Signature:
function addNotificationListener(name: "tablesChanged", handler: () => void): void;
Fired when another view of your plugin sends a broadcast message.
!!! tip
This is automatically handled when using broadcast.on(). You typically don't need to use this directly.
Usage:
import { addNotificationListener } from '@beekeeperstudio/plugin';
addNotificationListener('broadcast', ({ message }) => {
// Handle broadcast message
console.log('Received broadcast:', message);
});
Signature:
function addNotificationListener<Message extends JsonValue = JsonValue>(
name: "broadcast",
handler: (args: { message: Message }) => void
): void;
Fired when the application theme changes.
Usage:
import { addNotificationListener } from '@beekeeperstudio/plugin';
addNotificationListener('themeChanged', (appTheme) => {
// Apply new theme to your plugin
styleTag.textContent = `:root { ${params.cssString} }`;
});
Params schema:
See appTheme
!!! info "Internal Use" This notification is primarily for internal use.
Fired for various window events.
Usage:
import { addNotificationListener } from '@beekeeperstudio/plugin';
addNotificationListener('windowEvent', (params) => {
if (params.eventType === 'resize') {
// Handle window resize
}
});
Schema:
{
eventType: string;
eventClass: "MouseEvent" | "KeyboardEvent" | "PointerEvent" | "Event";
eventInitOptions: MouseEventInit | KeyboardEventInit | PointerEventInit;
}
Use removeNotificationListener to unsubscribe from events.
Usage:
import { addNotificationListener, removeNotificationListener } from '@beekeeperstudio/plugin';
const handler = () => {
console.log('Tables changed');
};
// Subscribe
addNotificationListener('tablesChanged', handler);
// Unsubscribe
removeNotificationListener('tablesChanged', handler);
Signature:
function removeNotificationListener(name: "tablesChanged", handler: (args: any) => void): void;
function removeNotificationListener<Message extends JsonValue = JsonValue>(name: "broadcast", handler: (args: any) => void): void;
function removeNotificationListener(name: "themeChanged", handler: (args: any) => void): void;
| Property | Type | Description |
|---|---|---|
rows | object[] | Array of result rows |
fields | Field[] | Array of field definitions |
rowCount | number | Number of rows returned |
affectedRows | number | Number of rows affected (for INSERT/UPDATE/DELETE) |
| Property | Type | Description |
|---|---|---|
name | string | Column name |
dataType | string | Column data type |
| Property | Type | Description |
|---|---|---|
name | string | Column name |
dataType | string | Column data type |
nullable | boolean | Whether column allows NULL values |
primaryKey | boolean | Whether column is part of primary key |
defaultValue | any | Default value for the column |
| Property | Type | Description |
|---|---|---|
name | string | Table name |
schema | string | Schema name (optional) |
Foreign key relationship information.
| Property | Type | Description |
|---|---|---|
isComposite | boolean | Whether the key involves multiple columns |
toTable | string | Target table name |
toSchema | string | Target schema name |
toColumn | string | string[] | Target column(s) |
fromTable | string | Source table name |
fromSchema | string | Source schema name |
fromColumn | string | string[] | Source column(s) |
constraintName | string | Constraint name (optional) |
onUpdate | string | ON UPDATE action (optional) |
onDelete | string | ON DELETE action (optional) |
| Property | Type | Description |
|---|---|---|
columnName | string | Column name |
position | number | Position in composite primary key |
| Property | Type | Description |
|---|---|---|
id | string | Index identifier |
table | string | Table name |
schema | string | Schema name |
name | string | Index name |
columns | IndexColumn[] | Array of index columns |
unique | boolean | Whether the index enforces uniqueness |
primary | boolean | Whether this is a primary key index |
nullsNotDistinct | boolean | For PostgreSQL 15+: whether nulls are treated as distinct (optional) |
| Property | Type | Description |
|---|---|---|
name | string | Column name |
order | 'ASC' | 'DESC' | '2d' | '2dsphere' | 'text' | 'geoHaystack' | 'hashed' | number | Sort order (optional) |
prefix | number | null | MySQL only: index prefix length (optional) |
| Property | Type | Description |
|---|---|---|
fields | { id: string; name: string; dataType?: string }[] | Array of field definitions |
rows | object[] | Array of result rows |
| Property | Type | Description |
|---|---|---|
connectionType | string | Alias for databaseType |
id | number | Connection ID |
workspaceId | number | Workspace ID |
connectionName | string | Name specified in connection form |
databaseType | DatabaseType | Type of database |
databaseName | string | Name of the database |
defaultSchema | string | Default schema (optional) |
readOnlyMode | boolean | Whether connection is read-only |
Context information for how a plugin view was opened.
| Property | Type | Description |
|---|---|---|
command | string | The command from manifest.json |
params | LoadViewParams | Context-specific parameters (optional) |
Parameters when a cell context menu is triggered.
| Property | Type | Description |
|---|---|---|
target | CellMenuTarget | Information about the clicked cell |
activeRange | ActiveRange | Currently selected range |
Parameters when a column header context menu is triggered.
| Property | Type | Description |
|---|---|---|
target | ColumnMenuTarget | Information about the clicked column |
activeRange | ActiveRange | Currently selected range |
Parameters when a row header context menu is triggered.
| Property | Type | Description |
|---|---|---|
target | RowMenuTarget | Information about the clicked row |
activeRange | ActiveRange | Currently selected range |
Parameters when the corner (top-left) context menu is triggered.
| Property | Type | Description |
|---|---|---|
target | CornerMenuTarget | Information about the selection |
activeRange | ActiveRange | Currently selected range |
Represents the currently selected range in a data table.
| Property | Type | Description |
|---|---|---|
rows | number[] | Array of selected row indices |
columns | string[] | Array of selected column names |
value | JsonValue[][] | 2D array of selected values |
| Property | Type | Description |
|---|---|---|
query | string | SQL query to populate (optional) |
| Property | Type | Description |
|---|---|---|
table | string | Table name |
schema | string | Schema name (optional) |
filters | TableFilter[] | Filters to apply (optional) |
database | string | Database name (optional) |
| Property | Type | Description |
|---|---|---|
table | string | Table name |
schema | string | Schema name (optional) |
database | string | Database name (optional) |
| Property | Type | Description |
|---|---|---|
field | string | Column name to filter |
type | '=' | '!=' | 'like' | 'not like' | '<' | '<=' | '>' | '>=' | 'in' | 'is' | 'is not' | Filter operator |
value | string | string[] | Filter value(s) (optional) |
op | 'AND' | 'OR' | Logical operator (optional) |
| Property | Type | Description |
|---|---|---|
data | string | Data to save |
fileName | string | Default file name |
encoding | 'utf8' | 'base64' | Data encoding (default: "utf8") |
filters | { name: string; extensions: string[] }[] | File type filters (optional) |
| Property | Type | Description |
|---|---|---|
palette | Record<string, string> | Key-value pairs of color names and hex codes |
cssString | string | Generated CSS rules for the theme |
type | ThemeType | Defines whether the theme is light or dark |
Union of supported database types:
'postgresql' | 'mysql' | 'mariadb' | 'sqlite' | 'sqlserver' | 'oracle' | 'mongodb' | 'cassandra' | 'clickhouse' | 'firebird' | 'bigquery' | 'redshift' | 'duckdb' | 'libsql' | 'redis' | 'surrealdb' | 'trino'
"dark" | "light"
string | number | boolean | null | Record<string, JsonValue> | JsonValue[]