diff options
Diffstat (limited to 'src/db/sqlite_new.zig')
| -rw-r--r-- | src/db/sqlite_new.zig | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/src/db/sqlite_new.zig b/src/db/sqlite_new.zig index 46706b8..36eaf61 100644 --- a/src/db/sqlite_new.zig +++ b/src/db/sqlite_new.zig @@ -25,7 +25,7 @@ pub fn Database(comptime T: type) type { // TODO: make functions out of `table` and `columns`: Table(Schema), []const Column(Schema, table) for readability? pub fn select(self: *Self, comptime table: std.meta.Tag(Schema), comptime columns: []const std.meta.Tag(@FieldType(Schema, @tagName(table)))) Select(Schema, table, columns) { _ = self; - std.debug.print("{any}\n", .{ columns }); + std.debug.print("{any}\n", .{columns}); return .{ // .handle = self.handle, }; @@ -152,17 +152,17 @@ fn Unique(comptime T: type) type { const Type = T.Type; // TODO: `contains(expected, str)` function const string = if (std.mem.count(u8, T.string, "UNIQUE") > 0) - @compileError(std.fmt.comptimePrint("Type `{s}` is already unique", .{ @typeName(T) })) + @compileError(std.fmt.comptimePrint("Type `{s}` is already unique", .{@typeName(T)})) else - std.fmt.comptimePrint("UNIQUE {s}", .{ T.string }); + std.fmt.comptimePrint("UNIQUE {s}", .{T.string}); }; } fn Default(comptime T: type, comptime value: T.Type) type { return struct { const Type = T.type; - const string = if(std.mem.count(u8, T.string, "DEFAULT") > 0) - @compileError(std.fmt.comptimePrint("Type `{s}` already has a default value", .{ @typeName(T) })) + const string = if (std.mem.count(u8, T.string, "DEFAULT") > 0) + @compileError(std.fmt.comptimePrint("Type `{s}` already has a default value", .{@typeName(T)})) else std.fmt.comptimePrint("{s} DEFAULT {}", .{ T.string, value }); }; @@ -202,12 +202,12 @@ fn Test(comptime Schema: type, comptime table: std.meta.Tag(Schema), comptime co fn Eql(comptime column: std.meta.Tag(ColumnUnion), value: @FieldType(ColumnUnion, @tagName(column))) type { return struct { - const fmt: []const u8 = std.fmt.comptimePrint("{s} = ", .{ @tagName(column) }); - const args: @Tuple(&.{ @TypeOf(value) }) = .{ value }; + const fmt: []const u8 = std.fmt.comptimePrint("{s} = ", .{@tagName(column)}); + const args: @Tuple(&.{@TypeOf(value)}) = .{value}; }; } // fn And() type { - // todo: concat fmt slices and args tuples + // todo: concat fmt slices and args tuples // } string: Node, @@ -236,10 +236,10 @@ test "schema" { const Schema = struct { contacts: Contacts, // contacts: struct { - // contact_id: Integer = .constrain(.primary_key), - // age: Integer = .unconstrained, - // contact_id: Integer(usize) = .constrain(.{ .primary_key = true }), - // first_name: Default(VarChar(255), "Hans"), + // contact_id: Integer = .constrain(.primary_key), + // age: Integer = .unconstrained, + // contact_id: Integer(usize) = .constrain(.{ .primary_key = true }), + // first_name: Default(VarChar(255), "Hans"), // }, }; @@ -254,10 +254,10 @@ test "schema" { const t: Test(@TypeOf(db).Schema, .contacts, &.{ .id, .first_name }) = .eql(.id, 42); // const t: Test(@TypeOf(db).Schema, .contacts, &.{ .id, .first_name }) = .op_and(.eql(.id, 42), .eql(.first_name, "name")); - std.debug.print("test output: {s}{}\n", switch (t.string) { .eql => |eq| .{ eq.fmt, eq.args } }); + std.debug.print("test output: {s}{}\n", switch (t.string) { + .eql => |eq| .{ eq.fmt, eq.args }, + }); const Int = Default(Unique(Integer(usize)), 42); - std.debug.print("default unique integer with default 42: {s}\n", .{ Int.string }); - - + std.debug.print("default unique integer with default 42: {s}\n", .{Int.string}); } |