plugin-postgresql-connector
Version:
NocoBase plugin for connecting to external PostgreSQL databases
116 lines (99 loc) • 3.75 kB
text/typescript
import { Plugin } from '@nocobase/client';
import { DatabaseOutlined, SearchOutlined, HistoryOutlined } from '@ant-design/icons';
// Import components
import { ConnectionForm } from './components/ConnectionForm';
import { QueryBuilder } from './components/QueryBuilder';
// Import pages
import ConnectionManager from './pages/ConnectionManager';
import QueryExecutor from './pages/QueryExecutor';
export class PostgreSQLConnectorPlugin extends Plugin {
async afterAdd() {
// Nothing to do after add
}
async beforeLoad() {
// Nothing to do before load
}
async load() {
// Register components
this.app.addComponents({
ConnectionForm,
QueryBuilder,
ConnectionManager,
QueryExecutor,
});
// Register routes
this.app.router.add('postgresql-connector', {
path: '/postgresql-connector',
Component: QueryExecutor,
});
this.app.router.add('postgresql-connector.connections', {
path: '/postgresql-connector/connections',
Component: ConnectionManager,
});
this.app.router.add('postgresql-connector.query-builder', {
path: '/postgresql-connector/query-builder',
Component: QueryExecutor,
});
// Add main menu item
this.app.pluginSettingsManager.add('postgresql-connector', {
title: 'PostgreSQL Connector',
icon: 'DatabaseOutlined',
Component: QueryExecutor,
aclSnippet: 'pm.postgresql-connector.configuration',
});
// Add menu items to admin menu
this.app.menu.add('postgresql-connector', {
title: 'PostgreSQL',
icon: 'DatabaseOutlined',
type: 'group',
});
this.app.menu.add('postgresql-connector.query-builder', {
title: 'Query Builder',
icon: 'SearchOutlined',
parent: 'postgresql-connector',
component: 'QueryExecutor',
});
this.app.menu.add('postgresql-connector.connections', {
title: 'Connections',
icon: 'DatabaseOutlined',
parent: 'postgresql-connector',
component: 'ConnectionManager',
});
this.app.menu.add('postgresql-connector.history', {
title: 'Query History',
icon: 'HistoryOutlined',
parent: 'postgresql-connector',
component: 'QueryExecutor',
});
// Register permissions
this.app.acl.allowMenuItemsBasedOnACL = true;
// Register locales
this.app.i18n.addResources('en-US', 'postgresql-connector', {
'PostgreSQL Connector': 'PostgreSQL Connector',
'Query Builder': 'Query Builder',
'Connections': 'Connections',
'Query History': 'Query History',
'Database Connection': 'Database Connection',
'Execute Query': 'Execute Query',
'Save Query': 'Save Query',
'Connection successful': 'Connection successful',
'Connection failed': 'Connection failed',
'Query executed successfully': 'Query executed successfully',
'Query execution failed': 'Query execution failed',
});
this.app.i18n.addResources('vi-VN', 'postgresql-connector', {
'PostgreSQL Connector': 'PostgreSQL Connector',
'Query Builder': 'Trình tạo Query',
'Connections': 'Kết nối',
'Query History': 'Lịch sử Query',
'Database Connection': 'Kết nối Database',
'Execute Query': 'Thực thi Query',
'Save Query': 'Lưu Query',
'Connection successful': 'Kết nối thành công',
'Connection failed': 'Kết nối thất bại',
'Query executed successfully': 'Query thực thi thành công',
'Query execution failed': 'Query thực thi thất bại',
});
}
}
export default PostgreSQLConnectorPlugin;