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