mirror of
https://github.com/oven-sh/bun
synced 2026-02-14 04:49:06 +00:00
more(sql) type fixes and tests (#16512)
This commit is contained in:
@@ -799,16 +799,16 @@ pub const ErrorResponse = struct {
|
||||
.{ "column", column, void },
|
||||
.{ "constraint", constraint, void },
|
||||
.{ "datatype", datatype, void },
|
||||
.{ "errno", code, i32 },
|
||||
// in the past this was set to i32 but postgres returns a strings lets keep it compatible
|
||||
.{ "errno", code, void },
|
||||
.{ "position", position, i32 },
|
||||
.{ "schema", schema, void },
|
||||
.{ "table", table, void },
|
||||
.{ "where", where, void },
|
||||
};
|
||||
|
||||
const error_code: JSC.Error =
|
||||
// https://www.postgresql.org/docs/8.1/errcodes-appendix.html
|
||||
if (code.toInt32() orelse 0 == 42601)
|
||||
if (code.eqlComptime("42601"))
|
||||
JSC.Error.ERR_POSTGRES_SYNTAX_ERROR
|
||||
else
|
||||
JSC.Error.ERR_POSTGRES_SERVER_ERROR;
|
||||
@@ -948,7 +948,10 @@ pub const DataRow = struct {
|
||||
for (0..remaining_fields) |index| {
|
||||
const byte_length = try reader.int4();
|
||||
switch (byte_length) {
|
||||
0 => break,
|
||||
0 => {
|
||||
var empty = Data.Empty;
|
||||
if (!try forEach(context, @intCast(index), &empty)) break;
|
||||
},
|
||||
null_int4 => {
|
||||
if (!try forEach(context, @intCast(index), null)) break;
|
||||
},
|
||||
|
||||
@@ -253,38 +253,28 @@ pub const Tag = enum(short) {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn toJSTypedArrayType(comptime T: Tag) JSValue.JSType {
|
||||
pub fn toJSTypedArrayType(comptime T: Tag) !JSValue.JSType {
|
||||
return comptime switch (T) {
|
||||
.int4_array => .Int32Array,
|
||||
// .int2_array => .Uint2Array,
|
||||
.float4_array => .Float32Array,
|
||||
// .float8_array => .Float64Array,
|
||||
else => @compileError("TODO: not implemented"),
|
||||
else => error.UnsupportedArrayType,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn byteArrayType(comptime T: Tag) type {
|
||||
pub fn byteArrayType(comptime T: Tag) !type {
|
||||
return comptime switch (T) {
|
||||
.int4_array => i32,
|
||||
// .int2_array => i16,
|
||||
.float4_array => f32,
|
||||
// .float8_array => f64,
|
||||
else => @compileError("TODO: not implemented"),
|
||||
else => error.UnsupportedArrayType,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn unsignedByteArrayType(comptime T: Tag) type {
|
||||
return comptime switch (T) {
|
||||
.int4_array => u32,
|
||||
// .int2_array => u16,
|
||||
.float4_array => f32,
|
||||
// .float8_array => f64,
|
||||
else => @compileError("TODO: not implemented"),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn pgArrayType(comptime T: Tag) type {
|
||||
return PostgresBinarySingleDimensionArray(byteArrayType(T));
|
||||
pub fn pgArrayType(comptime T: Tag) !type {
|
||||
return PostgresBinarySingleDimensionArray(try byteArrayType(T));
|
||||
}
|
||||
|
||||
fn toJSWithType(
|
||||
@@ -397,7 +387,7 @@ pub const Tag = enum(short) {
|
||||
|
||||
if (value.isAnyInt()) {
|
||||
const int = value.toInt64();
|
||||
if (int >= std.math.minInt(u32) and int <= std.math.maxInt(u32)) {
|
||||
if (int >= std.math.minInt(i32) and int <= std.math.maxInt(i32)) {
|
||||
return .int4;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user