VS Code 中的 PostgreSQL IDE
Postgres IDE in VS Code

原始链接: https://techcommunity.microsoft.com/blog/adforpostgresql/announcing-a-new-ide-for-postgresql-in-vs-code-from-microsoft/4414648

适用于Visual Studio Code (VS Code) 的全新PostgreSQL扩展简化了PostgreSQL数据库管理和开发。它解决了近期调查中开发者指出的低效问题,这些问题导致开发者在任务切换和调试上花费大量时间。其主要功能包括模式可视化、用于AI辅助数据库操作的“@pgsql”GitHub Copilot代理、与Azure Database for PostgreSQL集成和Entra ID身份验证的简化连接管理以及全面的数据库对象浏览器。 该扩展提供上下文感知的IntelliSense、SQL格式化和查询历史记录跟踪以提高生产力。“@pgsql”代理提供数据库和工作区上下文感知,从而能够为原型设计、调试和优化提供更智能的辅助。其执行多步任务的能力使其有别于基本的问答互动。 通过Entra ID简化的身份验证简化了安全性并降低了管理开销。凭借无缝的云集成和对效率的关注,PostgreSQL扩展使开发人员能够更快地构建创新型应用程序。从VS Code Marketplace (ms-ossdata.vscode-pgsql) 下载预览版并提供反馈以塑造未来的增强功能。您还需要安装GitHub Copilot和GitHub Copilot chat扩展。

微软发布了 VS Code 的 PostgreSQL IDE 扩展,旨在简化编辑器内的数据库管理。这解决了开发者经常在 VS Code 和专用数据库工具之间切换的常见需求。该扩展提供了模式可视化、查询执行以及与 GitHub Copilot 集成以进行 AI 辅助查询编写等功能。 这一公告在 Hacker News 上引发了讨论。一些用户称赞其简化工作流程并与 DataGrip 等现有工具竞争的潜力。另一些用户则对微软的开源方式表示担忧,指出闭源扩展和许可限制可能会影响商业用途以及与 VSCodium 等 VS Code 分支的兼容性。一些人认为微软正在追赶 JetBrain 的 DataGrip,后者提供了强大的数据库集成、智能 SQL 功能,并支持多种数据库系统。尽管存在许可证方面的担忧,但该扩展显示出前景,并满足了在 VS Code 环境中管理 PostgreSQL 的需求。

原文

We are excited to announce the public preview of the brand-new PostgreSQL extension for Visual Studio Code (VS Code), designed to simplify PostgreSQL database management and development workflows. With this extension, you can now manage database objects, draft queries with intelligent assistance from context-aware IntelliSense and our ‘@pgsql’ GitHub Copilot agent—all without ever leaving your favorite code editor.

Many of you face hurdles in managing time effectively, with 41% of developers struggling with task-switching, according to the 2024 StackOverflow Developer Survey. Additionally, the 2024 Stripe Developer Coefficient Report reveals that developers spend up to 50% of their time debugging and troubleshooting code and databases. These inefficiencies are further compounded by the absence of integrated tools that unify database management and application development.

The PostgreSQL extension for VS Code addresses these challenges head-on by integrating Postgres database tools and the @pgsql GitHub Copilot agent, providing a unified application development and database management experience. By integrating robust features such as Entra ID authentication for centralized identity management and deep Azure Database for PostgreSQL integration, this extension empowers you to focus on building innovative applications rather than wrestling with fragmented workflows.

The public preview release of the PostgreSQL extension for VS Code introduces a suite of powerful new capabilities that enhance productivity and streamline development for application developers working with Postgres.

Schema visualization is a breeze with our ‘right-click’ context menu options.

o   Right-click on the database entry in the Object Explorer and select “Visualize Schema”

 

Figure 1: Right-click on the database entry in the Object Explorer and select “Visualize Schema”
Single click to expand.
  • AI assistance directly within VS Code providing PostgreSQL database context reduces the PostgreSQL learning curve and improves developer productivity​.
  • Simplified interaction with PostgreSQL databases and development tools using natural language.
  • Commands such as "@pgsql" enable you to query databases, optimize schemas, and execute SQL operations with ease.
  • Context menus, such as “Rewrite Query”, “Explain Query”, “Analyze Query Performance” provide AI Intelligence inside the query editor window.
  • Real-time, expert-level guidance to help keep PostgreSQL databases performant and secure and improve code quality​.
Figure 2: Screenshot of the PostgreSQL Copilot Context Menu.
Single click to expand.

Using the PostgreSQL Copilot Context Menu, 

Figure 3: PostgreSQL Copilot Explain Query Context Menu in action.
Single click to expand.

GitHub Copilot Chat agent mode provides a database context aware intelligent assistant that can perform multi-stage tasks, moving beyond the question-and-answer chat experience. Agent mode allows the Copilot to bring in additional context from your workspace and, with permission, it can write and debug code on its own. Agent mode transforms PostgreSQL development by providing real-time, AI-driven guidance that simplifies complex tasks like app prototyping, debugging, schema optimization, and performance tuning.  

In this example, we’ll ask the agent to create a new database on a specific server in my Saved Connections and enable the PostGIS extension.

Figure 4: Using the @pgsql GitHub Copilot Chat in agent mode to create a new database from a natural language prompt.
Single click to expand.

The @pgsql agent begins by listing the server connections, connecting to the server ‘postgis’, drafts the script to modify the database and waits for permission to continue before making changes. Database modifications require explicit permission from the user.

  • Simplified connection management for local and cloud-hosted PostgreSQL instances.
  • Support for multiple connection profiles and connection string parsing for easy setup.
  • Direct browsing and filtering of Azure Database for PostgreSQL deployments.
  • Integration with Entra ID for centralized security and identity management.


Connect with ease to your existing Azure Database for PostgreSQL deployments with the “Browse Azure” option in the “Add New Connection” menu.

Figure 5: Connecting to an Azure Database for PostgreSQL instance using the Browse Azure option with Entra ID authentication.
Single click to expand.

 

Connect to local Docker deployments with the Parameters or Connection String option.

Figure 6: Connect to PostgreSQL in a local Docker deployment.
Single click to expand.
  • Streamlined Authentication: Eliminates the need for manual login, offering a seamless integration experience for you.
  • Automatic Token Refresh: Ensures uninterrupted connectivity and minimizes the risk of authentication timeouts during development.
  • Enhanced Security: Provides robust protection by leveraging Entra-ID's secure authentication protocols.
  • Time Efficiency: Reduces overhead by automating token management, allowing you to focus on coding rather than administrative tasks.
  • Enterprise Compatibility: Aligns with corporate security standards and simplifies access to PostgreSQL databases in enterprise environments.
  • User Consistency: You can use your existing Entra-ID credentials, avoiding the need to manage separate accounts.
  • Provides a structured view of database objects such as schemas, tables, and functions.
  • Enables creation, modification, and deletion of database objects.
Figure 7: View, manage, and query database objects within the Database Explorer.
Single click to expand.

Session query history is available below the Object Explorer. This allows you to quickly review previously run queries for reuse. 

 

Figure 8: Query History context menu detail.
Single click to expand.
  • Context-aware IntelliSense for auto-completion of SQL keywords, table names, and functions.
  • Syntax highlighting and auto-formatting for improved query readability.
  • Query history tracking for reusing previously executed queries.
Figure 9: Query editing with database context-aware IntelliSense.
Single click to expand.

The PostgreSQL extension for VS Code stands out in the crowded landscape of developer database management tools due to its unparalleled functionality and intuitive design. Here’s what makes it special:

  • Enhanced Productivity: Features like context-aware IntelliSense and SQL formatting save time and minimize errors.
  • pgsql GitHub Copilot Chat agent: Database and workspace context awareness, enabling smarter and more contextually relevant assistance for developers – combined with the ability to perform multi-step tasks.
  • Streamlined Onboarding: The Connection Manager ensures you can get started within minutes.
  • Improved Security: Entra ID integration provides robust access control and centralized identity management, including the ability to browse your Azure Database for PostgreSQL instances. 
  • Comprehensive Toolset: You can manage database objects, execute queries, and deploy instances all within VS Code.
  • Seamless Cloud Integration: Deep integration with Azure Database for PostgreSQL simplifies cloud database management.

Installing the PostgreSQL extension for VS Code is simple:

  1. Open the Extensions view in VS Code.
  2. Search for "PostgreSQL" in the Extensions Marketplace.
  3. Select and install the Preview PostgreSQL extension with the blue elephant seen in the screenshot below. 
Figure 10: PostgreSQL extension available in the Marketplace. Extension ID: (ms-ossdata.vscode-pgsql)

Also available in the online Visual Studio Code Marketplace. 

You will need the GitHub Copilot and GitHub Copilot chat extensions installed in VS Code to be able to log into their GitHub Account and use "@pgsql" in the chat interface to interact with their PostgreSQL database.

We value your insights. Use the built-in feedback tool in VS Code to share your thoughts and report issues. Your feedback will help us refine the extension and ensure it meets the needs of the developer community.

The PostgreSQL extension for VS Code offers significant enhancements to development efficiency and productivity. We encourage you to explore the public preview today and experience improved workflows with PostgreSQL databases.

To learn more and get started, visit: https://aka.ms/pg-vscode-docs

 

Special thanks to Jonathon Frost, Principal PM for all of his work on the @pgsql GitHub Copilot. 

联系我们 contact @ memedata.com