pg.zig
606
Stars
0
Forks
0
Watchers
0
Open Issues
未知
许可证
Zig
语言
创建时间
最近更新
项目能做什么
Zig 语言的原生 PostgreSQL 驱动与客户端。
来源:基于仓库元数据
· 内容以仓库实际 README 为准
使用说明 查看原始 README 原仓库文档
中文使用说明暂未生成。下面保留原仓库 README 摘录,命令与配置均以原文为准。
原始 README 摘录(英文原文,节选前 3000 字符)
# Native PostgreSQL driver for Zig
A native PostgresSQL driver / client for Zig. Supports [LISTEN](#listen--notify).
See or run [example/main.zig](https://github.com/karlseguin/pg.zig/blob/master/example/main.zig) for a number of examples.
## Zig Version
This is for Zig 0.17.0. See branches for other versions.
## Install
1) Add pg.zig as a dependency in your `build.zig.zon`:
```bash
zig fetch --save git+https://github.com/karlseguin/pg.zig#master
```
2) In your `build.zig`, add the `pg` module as a dependency to your program:
```zig
const pg_module = b.dependency("pg", .{}).module("pg");
// the executable from your executable/library
const exe = b.addExecutable(.{
.name = "example",
...
.imports = &.{
.{ .name = "pg", .module = pg_module },
},
});
```
## Example
```zig
var pool = try pg.Pool.init(io, allocator, .{
.size = 5,
.connect = .{
.port = 5432,
.host = "127.0.0.1",
},
.auth = .{
.username = "postgres",
.database = "postgres",
.password = "postgres",
.timeout = 10_000,
}
});
defer pool.deinit();
var result = try pool.query("select id, name from users where power > $1", .{9000});
defer result.deinit();
while (try result.next()) |row| {
const id = try row.get(i32, 0);
// this is only valid until the next call to next(), deinit() or drain()
const name = try row.get([]u8, 1);
}
```
## Pool
The pool holds up to `size` database connections. The `acquire()` method is used to retrieve a connection from the pool. When no idle connection is available and the pool holds fewer than `size` connections, `acquire()` opens a new one. A connection released in an invalid state (e.g. after an error mid-query) is closed, and a new one is opened the next time one is needed.
### init(io: std.Io, allocator: std.mem.allocator, opts: Opts) !\*Pool
Initializes a connection pool. Pool options are:
* `size` - Maximum number of connections. Defaults to `10`.
* `auth`: - See [Conn.auth](#authopts-opts-void)
* `connect`: - See the [Conn.open](#openallocator-stdmemallocator-opts-opts-conn).
* `timeout`: - The amount of time, in milliseconds, to wait for a connection to be available when `acquire()` is called.
* `connect_on_init_count`: - The # of connections in the pool to eagerly connect during `init`. Defaults to `null` which will initiliaze all connections (`size`). The remaining (`size - connect_on_init_count`) connections are opened on demand by `acquire()`. This can be set to `0`, to prevent `init` from failing except in extreme cases (i.e. OOM), but that will hide any configuration/connection issue until the first query is executed.
### initUri(io: std.Io, allocator: std.mem.Allocator, uri: std.Uri, opts: Opts) !\*Pool
Initializes a connection pool using a std.Uri. When using this function, the `auth` and `connect` fields of `opts` should **not** be set, as these will automatically set based on the provided `uri`.
```zig
const uri = try std.Uri.parse("postgresql://username:password@localhost:5432
阅读完整原文
商业机会分析 规则生成(AI 未配置)
综合评分 40.1 分。该项目在“个人可实施性”维度得 35 分,“付费可能性”维度得 20.0 分,差异化空间 70.0 分(评分依据见评分卡)。
面向细分需求的二次开发产品
| 产品构想 | 基于 pg.zig 的核心能力,聚焦一个更窄的场景(如某平台、某行业)做差异化。 |
| 目标用户 | 该细分场景用户 |
| 难度/周期 | 中 · 2~6 周 |
| 收费模式 | 买断制 / 订阅制 / 广告 |
| 竞争风险 | 细分需求规模需验证 |
| 依据 | AI 推测:基于项目主题标签的判断 |
以上为规则引擎基于仓库公开数据生成的参考结论,包含推测成分,不构成投资或创业承诺;配置 AI 后可获得更深入的分析。
报告会保存到 个人中心
竞品与相似项目 GitHub Search 真实检索
| 项目 | 中文简介 | Stars | 语言 |
|---|---|---|---|
| ZiglaCity/ZigsPG | 中文介绍暂未生成 A simple desktop application for generating random complex p |
13 | Python |
| pgvector/pgvector-zig | 中文介绍暂未生成 pgvector examples for Zig |
8 | Zig |
| batok/zig-pg-demo | 中文介绍暂未生成 A Zig example to access postgresql using the libpq C library |
2 | Zig |
| SOG-web/pg_query.zig | 中文介绍暂未生成 Zig bindings for libpg_query — the PostgreSQL parser library |
1 | C |
| xuanmang/zorm | 中文介绍暂未生成 Modern, lightweight ORM for Zig that doesn't hide your SQL. |
1 | Zig |
| vlad-a-barbu/zpg | 中文介绍暂未生成 zig pg |
0 | Zig |
以上为通过 GitHub 官方 Search API 检索的相似项目,功能差异与优劣势需进一步人工确认,配置 AI 后可生成对比分析。
项目优势与风险
| 技术成熟度 | 创建于 ,最近推送 |
| 社区活跃 | Star 606 / Fork 0 / Issue 0(数据支持,可自行核实) |
| 许可证 | 未检测到(需人工确认) |
| 主要风险 | 上游项目方向可能变化;同赛道竞争者较多(见竞品表);热度与需求不完全等价 |
安装与使用
快速开始(以仓库 README 为准)
git clone https://github.com/karlseguin/pg.zig.git cd pg.zig # 请阅读仓库 README 获取确切安装步骤(依赖、配置、启动命令)
术语说明:Docker=应用容器(把程序和依赖打包运行);API Key=调用外部服务的密钥;Git Clone=把仓库代码下载到本地。常见错误:API Key 未配置 / 端口占用 / 数据库连接失败,多数项目在 README 的 Troubleshooting 章节有说明。