Native PostgreSQL driver / client for Zig
0

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'lsn_xid_types'

Karl Seguin (Aug 20, 2025, 7:37 AM +0800) 2a1d14b6 cede61e9

+33 -6
+1
build.zig
··· 70 70 .test_runner = .{ .path = b.path("test_runner.zig"), .mode = .simple }, 71 71 }); 72 72 addLibs(lib_test, modules); 73 + lib_test.linkLibC(); 73 74 lib_test.addLibraryPath(std.Build.LazyPath{ .cwd_relative = "/opt/openssl/lib" }); 74 75 lib_test.addIncludePath(std.Build.LazyPath{ .cwd_relative = "/opt/openssl/include" }); 75 76 lib_test.linkSystemLibrary("crypto");
+11
src/result.zig
··· 1252 1252 try t.expectSlice(u8, &.{ 174, 47, 71, 95, 128, 112, 65, 183, 186, 51, 134, 187, 168, 137, 123, 222 }, row.get([]u8, 1)); 1253 1253 } 1254 1254 1255 + test "Result: lsn" { 1256 + var c = t.connect(.{}); 1257 + defer c.deinit(); 1258 + const sql = "select $1::pg_lsn + 1"; 1259 + var result = try c.query(sql, .{ 32788447688 }); 1260 + defer result.deinit(); 1261 + 1262 + const row = (try result.next()).?; 1263 + try t.expectEqual(32788447689, row.get(i64, 0)); 1264 + } 1265 + 1255 1266 test "Row: column names" { 1256 1267 var c = t.connect(.{}); 1257 1268 defer c.deinit();
+21 -6
src/types.zig
··· 93 93 } 94 94 95 95 pub fn decode(data: []const u8, data_oid: i32) i32 { 96 - lib.assertDecodeType(i32, &.{Int32.oid.decimal}, data_oid); 96 + lib.assertDecodeType(i32, &.{Int32.oid.decimal, Xid.oid.decimal}, data_oid); 97 97 return Int32.decodeKnown(data); 98 98 } 99 99 ··· 119 119 120 120 pub fn decode(data: []const u8, data_oid: i32) i64 { 121 121 switch (data_oid) { 122 - Timestamp.oid.decimal, TimestampTz.oid.decimal => return Timestamp.decode(data, data_oid), 122 + Timestamp.oid.decimal, TimestampTz.oid.decimal => return Timestamp.decodeKnown(data), 123 123 else => { 124 - lib.assertDecodeType(i64, &.{Int64.oid.decimal}, data_oid); 124 + lib.assertDecodeType(i64, &.{Int64.oid.decimal, PgLSN.oid.decimal, Xid8.oid.decimal}, data_oid); 125 125 return Int64.decodeKnown(data); 126 126 }, 127 127 } ··· 366 366 } 367 367 return out; 368 368 } 369 + }; 370 + 371 + pub const PgLSN = struct { 372 + pub const oid = OID.make(3220); 373 + const encoding = &binary_encoding; 374 + }; 375 + 376 + pub const Xid = struct { 377 + pub const oid = OID.make(28); 378 + const encoding = &binary_encoding; 379 + }; 380 + 381 + pub const Xid8 = struct { 382 + pub const oid = OID.make(5069); 383 + const encoding = &binary_encoding; 369 384 }; 370 385 371 386 pub const MacAddr = struct { ··· 1137 1152 if (value > 255 or value < 0) return error.IntWontFit; 1138 1153 return Char.encode(@intCast(value), buf, format_pos); 1139 1154 }, 1140 - Int64.oid.decimal => return Int64.encode(@intCast(value), buf, format_pos), 1155 + Int64.oid.decimal, PgLSN.oid.decimal, Xid8.oid.decimal => return Int64.encode(@intCast(value), buf, format_pos), 1141 1156 else => return error.BindWrongType, 1142 1157 }, 1143 1158 .int => switch (oid) { ··· 1145 1160 if (value > 32767 or value < -32768) return error.IntWontFit; 1146 1161 return Int16.encode(@intCast(value), buf, format_pos); 1147 1162 }, 1148 - Int32.oid.decimal => { 1163 + Int32.oid.decimal, Xid.oid.decimal => { 1149 1164 if (value > 2147483647 or value < -2147483648) return error.IntWontFit; 1150 1165 return Int32.encode(@intCast(value), buf, format_pos); 1151 1166 }, ··· 1155 1170 if (value > 255 or value < 0) return error.IntWontFit; 1156 1171 return Char.encode(@intCast(value), buf, format_pos); 1157 1172 }, 1158 - Int64.oid.decimal => { 1173 + Int64.oid.decimal, PgLSN.oid.decimal, Xid8.oid.decimal => { 1159 1174 if (value > 9223372036854775807 or value < -9223372036854775808) { 1160 1175 return error.IntWontFit; 1161 1176 }