| author | |
| committer | |
| log | f2163337d5bbd410eec613f9efa6355fffb7a599 |
| tree | ed7524a3087a2d0fab5588a4a5959f6633aebe25 |
| parent | 66ae64bdb507e6fdd066683c331e3aaa8350a8c7 |
| signature | Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw |
3 files changed, 29 insertions(+), 0 deletions(-)
src/lib.zig+12| ... | ... | @@ -86,8 +86,20 @@ pub const Engine = union(DriverType) { |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | pub fn addColumn(engine: *Engine, alloc: std.mem.Allocator, comptime table_name: []const u8, comptime col_name: []const u8, T: type) !void { |
| 89 | if (switch (@typeInfo(T)) { | |
| 90 | .@"struct", .@"enum", .@"union" => @hasDecl(T, "foreign_table"), | |
| 91 | else => false, | |
| 92 | }) { | |
| 93 | return addColumnForeign(engine, alloc, table_name, col_name, T, T.foreign_table, T.foreign_column); | |
| 94 | } | |
| 89 | 95 | return switch (engine.*) { |
| 90 | 96 | inline else => |*e| e.addColumn(alloc, table_name, col_name, T), |
| 91 | 97 | }; |
| 92 | 98 | } |
| 99 | ||
| 100 | pub fn addColumnForeign(engine: *Engine, alloc: std.mem.Allocator, comptime table_name: []const u8, comptime col_name: []const u8, T: type, comptime table_name2: []const u8, comptime col_name2: []const u8) !void { | |
| 101 | return switch (engine.*) { | |
| 102 | inline else => |*e| e.addColumnForeign(alloc, table_name, col_name, T, table_name2, col_name2), | |
| 103 | }; | |
| 104 | } | |
| 93 | 105 | }; |
src/postgresql.zig+11| ... | ... | @@ -284,6 +284,17 @@ pub fn addColumn(driver: *Driver, alloc: std.mem.Allocator, comptime table_name: |
| 284 | 284 | @panic("TODO"); |
| 285 | 285 | } |
| 286 | 286 | |
| 287 | pub fn addColumnForeign(driver: *Driver, alloc: std.mem.Allocator, comptime table_name: []const u8, comptime col_name: []const u8, T: type, comptime table_name2: []const u8, comptime col_name2: []const u8) !void { | |
| 288 | _ = driver; | |
| 289 | _ = alloc; | |
| 290 | _ = table_name; | |
| 291 | _ = col_name; | |
| 292 | _ = T; | |
| 293 | _ = table_name2; | |
| 294 | _ = col_name2; | |
| 295 | @panic("TODO"); | |
| 296 | } | |
| 297 | ||
| 287 | 298 | pub fn nameForType(T: type) []const u8 { |
| 288 | 299 | if (@typeInfo(T) == .optional) { |
| 289 | 300 | return nameForType2(T); |
src/sqlite3.zig+6| ... | ... | @@ -107,6 +107,12 @@ pub fn addColumn(self: *Self, alloc: std.mem.Allocator, comptime table_name: []c |
| 107 | 107 | try self.exec(alloc, comptime std.fmt.comptimePrint("alter table {s} add \"{s}\" {s}", .{ table_name, col_name, nameForType(T) }), .{}); |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | pub fn addColumnForeign(self: *Self, alloc: std.mem.Allocator, comptime table_name: []const u8, comptime col_name: []const u8, T: type, comptime table_name2: []const u8, comptime col_name2: []const u8) !void { | |
| 111 | const t = tracer.trace(@src(), " {s}.{s}", .{ table_name, col_name }); | |
| 112 | defer t.end(); | |
| 113 | try self.exec(alloc, comptime std.fmt.comptimePrint("alter table {s} add \"{s}\" {s} references \"{s}\" (\"{s}\")", .{ table_name, col_name, nameForType(T), table_name2, col_name2 }), .{}); | |
| 114 | } | |
| 115 | ||
| 110 | 116 | pub fn nameForType(T: type) []const u8 { |
| 111 | 117 | if (@typeInfo(T) == .optional) { |
| 112 | 118 | return nameForType2(@typeInfo(T).optional.child); |