Files
bun.sh/src/sql/shared/ColumnIdentifier.zig
Ciro Spaciari ecbf103bf5 feat(MYSQL) Bun.SQL mysql support (#21968)
### What does this PR do?
Add MySQL support, Refactor will be in a followup PR
### How did you verify your code works?
A lot of tests

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: cirospaciari <6379399+cirospaciari@users.noreply.github.com>
2025-08-21 15:28:15 -07:00

39 lines
1.1 KiB
Zig

pub const ColumnIdentifier = union(enum) {
name: Data,
index: u32,
duplicate: void,
pub fn init(name: Data) !@This() {
if (switch (name.slice().len) {
1..."4294967295".len => true,
0 => return .{ .name = .{ .empty = {} } },
else => false,
}) might_be_int: {
// use a u64 to avoid overflow
var int: u64 = 0;
for (name.slice()) |byte| {
int = int * 10 + switch (byte) {
'0'...'9' => @as(u64, byte - '0'),
else => break :might_be_int,
};
}
// JSC only supports indexed property names up to 2^32
if (int < std.math.maxInt(u32))
return .{ .index = @intCast(int) };
}
return .{ .name = .{ .owned = try name.toOwned() } };
}
pub fn deinit(this: *@This()) void {
switch (this.*) {
.name => |*name| name.deinit(),
else => {},
}
}
};
const std = @import("std");
const Data = @import("../shared/Data.zig").Data;