开源项目 gopgext 正式推出,该工具链基于 TinyGo 编译器构建,允许开发者使用纯 Go 代码编写 PostgreSQL 数据库扩展 1。通过这一创新方案,原本主要依赖 C 语言的 PostgreSQL 扩展开发领域引入了 Go 语言支持 1。
在技术实现上,开发者只需在 Go 函数前添加 //gopgext:function 注释标记,即可将其转换为 SQL 函数,随后工具会自动生成所需的 C 语言胶水代码、安装脚本及控制文件 1。该方案兼容多种 Go 标准库组件,包括 fmt、regexp、encoding/json 以及 crypto/* 系列包 1。同时,它支持广泛的数据类型映射,涵盖字符串、数字、数组、NULLs、集合、行、时间戳、UUID 和 JSON 等 1。
gopgext 不仅限于基础功能,还支持开发触发器、聚合函数、GiST/GIN/SP-GiST/BRIN 操作符类、索引访问方法、外部数据包装器以及查询钩子等复杂数据库对象 1。该项目已在实际移植测试中验证了可行性,成功将 pgcrypto、hstore、pg_stat_statements 和 cube 等 PostgreSQL 官方 contrib 模块迁移至 Go 环境并通过了回归测试 1。此外,多个由该工具生成的 Go 扩展能够在同一后端安全共存 1。
从技术路径来看,gopgext 采用了与 gokm(用于构建 Linux 内核模块的项目)相同的架构策略,即结合自定义 TinyGo 目标、C 运行时以及生成的胶水代码 1。
A new open-source project named gopgext allows developers to build PostgreSQL database extensions using pure Go code by leveraging the TinyGo compiler. 1 The toolchain supports the creation of various extension components, including triggers, aggregate functions, GiST/GIN/SP-GiST/BRIN operator classes, index access methods, foreign data wrappers, and query hooks. 1 This approach mirrors the technical path used by gokm, a project for building Linux kernel modules, utilizing a custom TinyGo target combined with C runtime integration and generated glue code. 1
The development workflow is streamlined through specific annotations; marking a Go function with the //gopgext:function comment automatically converts it into an SQL function. 1 During this process, the tool generates the necessary C language glue code, installation scripts, and control files. 1 The system supports standard library components such as fmt, regexp, encoding/json, and crypto/*, along with comprehensive type mappings for strings, numbers, arrays, NULLs, collections, rows, timestamps, UUIDs, and JSON. 1
Feasibility has been demonstrated through successful ports of official PostgreSQL contrib modules, including pgcrypto, hstore, pg_stat_statements, and cube, which passed regression testing. 1 Furthermore, the solution ensures safe coexistence, allowing multiple Go-based extensions to operate simultaneously within a single backend instance. 1
评论
还没有评论,欢迎留下第一条。