UNPKG

plugin-postgresql-connector

Version:

NocoBase plugin for connecting to external PostgreSQL databases

136 lines (96 loc) 4.18 kB
# NocoBase PostgreSQL Connector Plugin [![NPM version](https://img.shields.io/npm/v/@nocobase/plugin-postgresql-connector.svg?style=flat)](https://npmjs.org/package/@nocobase/plugin-postgresql-connector) [![NPM downloads](http://img.shields.io/npm/dm/@nocobase/plugin-postgresql-connector.svg?style=flat)](https://npmjs.org/package/@nocobase/plugin-postgresql-connector) [![License](https://img.shields.io/npm/l/@nocobase/plugin-postgresql-connector.svg)](https://npmjs.org/package/@nocobase/plugin-postgresql-connector) > Connect to and interact with external PostgreSQL databases directly from your NocoBase application. ## Features - **Connection Management**: Create, test, and manage multiple PostgreSQL database connections - **Query Builder**: Write and execute SQL queries with syntax highlighting and auto-completion - **Schema Browser**: Browse tables, views, functions, and other database objects - **Result Viewer**: View query results in a tabular format with pagination - **Saved Queries**: Save and organize frequently used queries - **Security**: Secure connection credentials with encryption ## Installation ### As a NocoBase Plugin ```bash # Go to your NocoBase project directory cd my-nocobase-app # Install the plugin yarn add @nocobase/plugin-postgresql-connector # Enable the plugin yarn pm enable @nocobase/plugin-postgresql-connector # Restart NocoBase yarn start ``` ### Development Setup ```bash # Clone NocoBase repository git clone https://github.com/nocobase/nocobase.git cd nocobase # Install dependencies yarn install # Create a new plugin yarn pm create @nocobase/plugin-postgresql-connector # Start development server yarn dev ``` ## Usage ### Creating a Connection 1. Navigate to "Settings" > "Plugins" > "PostgreSQL Connector" 2. Click "Add Connection" 3. Enter connection details: - Name: A friendly name for your connection - Host: PostgreSQL server hostname or IP address - Port: PostgreSQL server port (default: 5432) - Database: Database name - Username: Database username - Password: Database password - SSL: Enable SSL connection 4. Click "Test Connection" to verify the connection 5. Click "Create Connection" to save ### Executing Queries 1. Navigate to "PostgreSQL Connector" > "Query" 2. Select a connection from the dropdown 3. Enter your SQL query in the editor 4. Click "Execute Query" to run the query 5. View results in the table below ### Browsing Schema 1. Select a connection from the dropdown 2. The schema browser will load on the right side 3. Expand tables, views, or functions to see their structure 4. Click on a table or view to generate a SELECT query 5. Click on a function to generate a function call ### Saving Queries 1. Write a query in the editor 2. Click "Save Query" 3. Enter a name and description for the query 4. Select the query type (SELECT, PROCEDURE, FUNCTION, VIEW) 5. Click "Save" ## Configuration The plugin supports the following environment variables: ```bash # .env ENCRYPTION_KEY=your-secret-encryption-key POSTGRESQL_CONNECTOR_MAX_CONNECTIONS=10 POSTGRESQL_CONNECTOR_CONNECTION_TIMEOUT=5000 ``` ## API Reference See the [API Documentation](./docs/api.md) for details on the available APIs. ## Security This plugin implements several security measures: 1. **Password Encryption**: Connection passwords are encrypted before storing in the database 2. **SQL Injection Prevention**: All queries use parameterized statements 3. **Access Control**: Integration with NocoBase ACL system 4. **Input Validation**: Comprehensive validation of all inputs ## Contributing We welcome contributions! Please see our [Contributing Guide](./CONTRIBUTING.md) for details. ## License [MIT](./LICENSE) ## Support - [GitHub Issues](https://github.com/nocobase/nocobase/issues) - [Documentation](https://docs.nocobase.com) - [Community Forum](https://forum.nocobase.com) ## Acknowledgements - [PostgreSQL](https://www.postgresql.org/) - [Node-Postgres](https://node-postgres.com/) - [NocoBase](https://www.nocobase.com/)