authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-05-21 20:16:07 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-05-21 20:16:07 -07:00
logc6169eba24ddab92c70731cb57c2017526fcb27e
treefa2f55641edfecff1e0d4e125fd10b6cc094ec05
parent80e34e73bbaed04800ff5e7ee44416606c3039f8
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

postgresql: clean up logs


1 files changed, 4 insertions(+), 10 deletions(-)

src/postgresql.zig+4-10
...@@ -22,9 +22,9 @@ bufw: nio.BufferedWriter(4096, net.Stream),...@@ -22,9 +22,9 @@ bufw: nio.BufferedWriter(4096, net.Stream),
22bufr: nio.BufferedReader(4096, net.Stream),22bufr: nio.BufferedReader(4096, net.Stream),
2323
24pub fn connect(allocator: std.mem.Allocator, connect_s: [:0]const u8) !Driver {24pub fn connect(allocator: std.mem.Allocator, connect_s: [:0]const u8) !Driver {
25 std.log.scoped(.zorm).info("connecting to {s} @ {s}", .{ "postgresql", connect_s });
26 const connect_url = try url.URL.parse(allocator, connect_s, null);25 const connect_url = try url.URL.parse(allocator, connect_s, null);
27 defer allocator.free(connect_url.href);26 defer allocator.free(connect_url.href);
27 std.log.scoped(.zorm).info("connecting to {s} @ postgresql://{s}{s}", .{ "postgresql", connect_url.hostname, connect_url.pathname });
2828
29 const addr: net.Address = try .fromUrl(&connect_url, allocator);29 const addr: net.Address = try .fromUrl(&connect_url, allocator);
30 const conn = try addr.tcpConnect();30 const conn = try addr.tcpConnect();
...@@ -64,9 +64,7 @@ pub fn connect(allocator: std.mem.Allocator, connect_s: [:0]const u8) !Driver {...@@ -64,9 +64,7 @@ pub fn connect(allocator: std.mem.Allocator, connect_s: [:0]const u8) !Driver {
64 const t: BackendMessageType = @enumFromInt(try bufr.readByte());64 const t: BackendMessageType = @enumFromInt(try bufr.readByte());
65 std.debug.assert(t == .Authentication);65 std.debug.assert(t == .Authentication);
66 const auth_len = try bufr.readInt(u32, .big);66 const auth_len = try bufr.readInt(u32, .big);
67 std.log.warn("auth_len={d}", .{auth_len});
68 const auth = try bufr.readInt(u32, .big);67 const auth = try bufr.readInt(u32, .big);
69 std.log.warn("auth={d}", .{auth});
70 switch (auth) {68 switch (auth) {
71 10 => { // AuthenticationSASL69 10 => { // AuthenticationSASL
72 const methods = try bufr.readAlloc(allocator, auth_len - 4 - 4);70 const methods = try bufr.readAlloc(allocator, auth_len - 4 - 4);
...@@ -76,7 +74,6 @@ pub fn connect(allocator: std.mem.Allocator, connect_s: [:0]const u8) !Driver {...@@ -76,7 +74,6 @@ pub fn connect(allocator: std.mem.Allocator, connect_s: [:0]const u8) !Driver {
76 while (methods_iter.next()) |method| {74 while (methods_iter.next()) |method| {
77 const method_z = method.ptr[0..method.len :0];75 const method_z = method.ptr[0..method.len :0];
78 if (method_z.len == 0) break;76 if (method_z.len == 0) break;
79 std.log.warn("method={s}", .{method_z});
8077
81 // https://datatracker.ietf.org/doc/html/rfc767778 // https://datatracker.ietf.org/doc/html/rfc7677
82 // https://datatracker.ietf.org/doc/html/rfc580279 // https://datatracker.ietf.org/doc/html/rfc5802
...@@ -198,7 +195,6 @@ pub fn connect(allocator: std.mem.Allocator, connect_s: [:0]const u8) !Driver {...@@ -198,7 +195,6 @@ pub fn connect(allocator: std.mem.Allocator, connect_s: [:0]const u8) !Driver {
198 std.debug.assert(ok == 12);195 std.debug.assert(ok == 12);
199 const data = try bufr.readAlloc(allocator, len - 8);196 const data = try bufr.readAlloc(allocator, len - 8);
200 defer allocator.free(data);197 defer allocator.free(data);
201 std.log.warn("AuthenticationSASLFinal = {s}", .{data});
202 }198 }
203 { //<-AuthenticationOk199 { //<-AuthenticationOk
204 const t2: BackendMessageType = @enumFromInt(try bufr.readByte());200 const t2: BackendMessageType = @enumFromInt(try bufr.readByte());
...@@ -208,7 +204,6 @@ pub fn connect(allocator: std.mem.Allocator, connect_s: [:0]const u8) !Driver {...@@ -208,7 +204,6 @@ pub fn connect(allocator: std.mem.Allocator, connect_s: [:0]const u8) !Driver {
208 std.debug.assert(len == 8);204 std.debug.assert(len == 8);
209 const ok = try bufr.readInt(u32, .big);205 const ok = try bufr.readInt(u32, .big);
210 std.debug.assert(ok == 0);206 std.debug.assert(ok == 0);
211 std.log.warn("AuthenticationOk", .{});
212 }207 }
213 }208 }
214 }209 }
...@@ -267,10 +262,9 @@ pub fn collect(driver: *Driver, alloc: std.mem.Allocator, comptime T: type, comp...@@ -267,10 +262,9 @@ pub fn collect(driver: *Driver, alloc: std.mem.Allocator, comptime T: type, comp
267//262//
268263
269pub fn doesTableExist(driver: *Driver, alloc: std.mem.Allocator, name: []const u8) !bool {264pub fn doesTableExist(driver: *Driver, alloc: std.mem.Allocator, name: []const u8) !bool {
270 _ = driver;265 const t = tracer.trace(@src(), " {s}", .{name});
271 _ = alloc;266 defer t.end();
272 _ = name;267 return try driver.first(alloc, bool, "SELECT EXISTS ( SELECT FROM pg_tables WHERE schemaname = ? AND tablename = ? )", .{ "public", name }) orelse unreachable;
273 @panic("TODO");
274}268}
275269
276pub fn hasColumnWithName(driver: *Driver, alloc: std.mem.Allocator, comptime table: []const u8, comptime column: []const u8) !bool {270pub fn hasColumnWithName(driver: *Driver, alloc: std.mem.Allocator, comptime table: []const u8, comptime column: []const u8) !bool {