From d0efb5a5ea535c5379fcba833374ed9955356d5e Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Fri, 17 Oct 2025 21:52:31 +0200 Subject: [PATCH] Connect: Add Zig --- docs/_assets/icon/zig-logo.png | Bin 0 -> 2374 bytes docs/connect/index.md | 15 ++++++ docs/connect/zig/index.md | 90 +++++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 docs/_assets/icon/zig-logo.png create mode 100644 docs/connect/zig/index.md diff --git a/docs/_assets/icon/zig-logo.png b/docs/_assets/icon/zig-logo.png new file mode 100644 index 0000000000000000000000000000000000000000..1c310a2a8a5d1e32e7e107d898ce26a28ba458ce GIT binary patch literal 2374 zcmY+Gc|2768^;eR+qEUzm`&jplNzQ_vJ6>jk_gRMN*Wo<&5P9EABODHG;n zq-?YlCc`0!5;Kt^*uxwaTFgX=LA00!dsvQyUrAVK3G87AC?_*fvJf8f2M}g1VZSBi z5SSoW$%HUUMw1a_4=_Py@Bs2<;l*VHxECyxy@Kmut*kF>@^C3H3*`{FKqi-;n9MK9 z+fqvz`AG6DWFsxj|AQc_k)P+%JpTt-Y6NfkKOKKO%k$sb zeH-$7rF^v?m2&y_%I`I@zOpj`QH$?flHjkf=cuo@AEW>*Q&d{MLRnQsUF|0gElnNm zmAZPX4D^i*5ymJa28}gYv)at`XY;j|7VB|V8}J)#tTz!h+uGZ0b=cedHiYNbvs9u!Gb?5r=7!QL!<<97%{jmU!Z1a!P7?#+l5V?6dUz z3yh+|l1qP-{#jNIRxm5Ca;mvEuGiG^>Tdnj(0Kda-TM!k9zJ@^f7;U4+Wx$wv+ISR zr}t%l->ZSa*KdY~-~K%^Iwl-{_kQBT$4`@=r@lrPDbYPJq$PpK4G%sba8pp%6_Yz|L{06E81>JR? zmOC%_+B~OTZg$NiUe=DwFdOm)=SivRl1DTDM0_sId9L0tKA$y>+xikPx7;1?mWRKW8PuaXVWP4H9ZQaHg zg;$5nX-dN-AMVgd8QgXSgzm&!#=92;bSjrONpKHnvPq!LW^vUY(q`>fJg=U{3o{36 zR-MXp@3l%4W*y~AAEa~tqA_Dr54Xlg;xf4#k_m;x1M^yk)M7q;^bEIh@Pm}-T}213 z9>mhqPbNm_)89M^TW4M99;)FmgQw?}9f;mSPaB(hCWKjzzj3u9kIw5|wtrpf{&ZoF zTFjZl9YfwDSF2{g(V(1L4T>&<;e^TRc&MaSJGKjGnIOcUyX~~YZ@5&CplCLk-`zk- zWScsVtdV%o`iv4IQVbBagBVsQb&52mjmQ_+JMAzEx;uZw=tMTZv$keaA%3xbsw0|k z8y)vRC-c`g;DxU!T<7H@dZt6n?nGTxt017|ehlBshwQQ{J-10Cc0waw%k$f^B4ZwAi0dp|0UztBiJWd7&OA*^VAuo@NmCL>7g5 zf42#FB+&Aba?81M0*fRbI^8M$s=qnZv2R;0g=+u6RlAhLdsR0W6~O~YVn>gd4UdY*E$iPY>8g}SiY#mBywLM10*cPrGj`u4h5 z)1#R%+BM=Dg9^9 zSAV(27)()}4tyj&0H(SR#V4{mPgw;wT4mr%e{HhtO3C-Gb4>e$G8%zahT=UwjW>@0 z=f=DDDIF;WH4}!n0CqorOp8dZ%$}DDt2qJui0Z zS+bU}`PxErF@LdYJ~%N!IgAvZ0+%M&WNl>Mbo$_EaNThAIT|A5rrif?gX^ey%oBo! zzDJ0#xy#@To<6f@Xve;!orW(OFd-_@Z5ep_!k+oYxMg{}6kyO}B)v@CwtT%fLOmRj zlPtsXZhXhy4>WvXhiQ*%u=g^2(Z?wpZ3>oZgpo#0AB`Az^Hbd^lHZogIRIbh2|@H& z(wUo7V#jXWOE`1PIy{B}+czs%{Lu|_kyNla*eT|TdDj*{Qz77n&)Hvy TCa6`i|3Y5dz1^-852XJKn@6s9 literal 0 HcmV?d00001 diff --git a/docs/connect/index.md b/docs/connect/index.md index ffe0cae1..7056d8ad 100644 --- a/docs/connect/index.md +++ b/docs/connect/index.md @@ -113,6 +113,20 @@ CrateDB drivers and adapters for supported programming languages, frameworks, an :::: +::::{grid-item-card} Zig +:link: connect-zig +:link-type: ref +:link-alt: Connect to CrateDB using Zig +:padding: 3 +:text-align: center +:class-card: sd-pt-3 +:class-body: sd-fs-1 +:class-title: sd-fs-6 +```{image} /_assets/icon/zig-logo.png +:height: 50px +``` +:::: + ::::: @@ -187,6 +201,7 @@ javascript php python ruby +zig/index natural All drivers ``` diff --git a/docs/connect/zig/index.md b/docs/connect/zig/index.md new file mode 100644 index 00000000..3c8b7028 --- /dev/null +++ b/docs/connect/zig/index.md @@ -0,0 +1,90 @@ +(connect-zig)= + +# Zig + +:::{div} sd-text-muted +Connect to CrateDB from Zig applications. +::: + +:::{rubric} About +::: + +[pg.zig] is a native PostgreSQL driver / client for Zig. + +:::{rubric} Synopsis +::: + +`build.zig` +```zig +const std = @import("std"); + +pub fn build(b: *std.Build) void { + + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + + const exe = b.addExecutable(.{ + .name = "example", + .root_module = b.createModule(.{ + .root_source_file = b.path("example.zig"), + .target = b.graph.host, + }) + }); + + const pg = b.dependency("pg", .{ + .target = target, + .optimize = optimize, + }); + exe.root_module.addImport("pg", pg.module("pg")); + + b.installArtifact(exe); +} +``` +`example.zig` +```zig +const std = @import("std"); +const builtin = @import("builtin"); + +const pg = @import("pg"); + +pub fn main() !void { + + var gpa = std.heap.GeneralPurposeAllocator(.{}){}; + const allocator = if (builtin.mode == .Debug) gpa.allocator() else std.heap.c_allocator; + + const uri = try std.Uri.parse("postgresql://crate:crate@localhost/doc?sslmode=disable"); + var pool = try pg.Pool.initUri(allocator, uri, .{.size=5, .timeout=5_000}); + defer pool.deinit(); + + var result = try pool.query("SELECT mountain, height FROM sys.summits ORDER BY height DESC LIMIT 3", .{}); + defer result.deinit(); + + while (try result.next()) |row| { + const mountain = row.get([]u8, 0); + const height = row.get(i32, 1); + std.debug.print("{s}: {d}\n", .{mountain, height}); + } + +} +``` + +:::{include} ../_cratedb.md +::: +```shell +zig fetch --save git+https://github.com/karlseguin/pg.zig#master +zig build +./zig-out/bin/example +``` + +:::{rubric} CrateDB Cloud +::: + +For connecting to CrateDB Cloud, use the `sslmode=require` parameter, +and replace username, password, and hostname with values matching your +environment. +```zig +const uri = try std.Uri.parse("postgresql://admin:password@testcluster.cratedb.net:5432/doc?sslmode=require"); +``` + + +[pg.zig]: https://github.com/karlseguin/pg.zig