Skip to content

Commit de80888

Browse files
committed
Driver/Zig: Add dedicated page
1 parent 1d3251e commit de80888

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed

docs/_assets/icon/zig-logo.png

2.32 KB
Loading

docs/connect/index.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,20 @@ CrateDB drivers and adapters for supported programming languages, frameworks, an
113113

114114
::::
115115

116+
::::{grid-item-card} Zig
117+
:link: connect-zig
118+
:link-type: ref
119+
:link-alt: Connect to CrateDB using Zig
120+
:padding: 3
121+
:text-align: center
122+
:class-card: sd-pt-3
123+
:class-body: sd-fs-1
124+
:class-title: sd-fs-6
125+
```{image} /_assets/icon/zig-logo.png
126+
:height: 50px
127+
```
128+
::::
129+
116130
:::::
117131

118132

@@ -187,6 +201,7 @@ javascript
187201
php
188202
python
189203
ruby
204+
zig
190205
natural
191206
All drivers <drivers>
192207
```

docs/connect/zig.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
(connect-zig)=
2+
3+
# Zig
4+
5+
:::{div} sd-text-muted
6+
Connect to CrateDB from Zig applications.
7+
:::
8+
9+
:::{rubric} About
10+
:::
11+
12+
[pg.zig] is a native PostgreSQL driver / client for Zig.
13+
14+
:::{rubric} Synopsis
15+
:::
16+
17+
`build.zig.zon`
18+
```shell
19+
zig fetch --save git+https://github.com/karlseguin/pg.zig#master
20+
```
21+
`build.zig`
22+
```zig
23+
const pg = b.dependency("pg", .{
24+
.target = target,
25+
.optimize = optimize,
26+
});
27+
exe.root_module.addImport("pg", pg.module("pg"));
28+
```
29+
`example.zig`
30+
```zig
31+
var pool = try pg.Pool.init(allocator, .{
32+
.size = 5,
33+
.connect = .{
34+
.host = "localhost",
35+
.port = 5432,
36+
},
37+
.auth = .{
38+
.username = "crate",
39+
.password = "crate",
40+
.database = "doc",
41+
.timeout = 10_000,
42+
}
43+
});
44+
defer pool.deinit();
45+
46+
var result = try pool.query("SELECT mountain, height FROM sys.summits ORDER BY height DESC LIMIT 3");
47+
defer result.deinit();
48+
49+
while (try result.next()) |row| {
50+
const mountain = row.get([]u8, 0);
51+
const height = row.get(i32, 1);
52+
std.debug.print("{s}: {d}", .{mountain, height});
53+
}
54+
```
55+
56+
:::{rubric} See also
57+
:::
58+
59+
- [Using PostgreSQL with Zig]
60+
61+
62+
[Using PostgreSQL with Zig]: https://medium.com/@swindlers-inc/using-postgresql-with-zig-203ab93d5b97
63+
[pg.zig]: https://github.com/karlseguin/pg.zig

0 commit comments

Comments
 (0)