mirror of
https://github.com/oven-sh/bun
synced 2026-02-11 19:38:58 +00:00
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>
This commit is contained in:
@@ -59,44 +59,20 @@ pub fn createPostgresError(
|
||||
message: []const u8,
|
||||
options: PostgresErrorOptions,
|
||||
) bun.JSError!JSValue {
|
||||
const bun_ns = (try globalObject.toJSValue().get(globalObject, "Bun")).?;
|
||||
const sql_constructor = (try bun_ns.get(globalObject, "SQL")).?;
|
||||
const pg_error_constructor = (try sql_constructor.get(globalObject, "PostgresError")).?;
|
||||
|
||||
const opts_obj = JSValue.createEmptyObject(globalObject, 0);
|
||||
opts_obj.put(globalObject, jsc.ZigString.static("code"), jsc.ZigString.init(options.code).toJS(globalObject));
|
||||
|
||||
if (options.errno) |errno| opts_obj.put(globalObject, jsc.ZigString.static("errno"), jsc.ZigString.init(errno).toJS(globalObject));
|
||||
if (options.detail) |detail| opts_obj.put(globalObject, jsc.ZigString.static("detail"), jsc.ZigString.init(detail).toJS(globalObject));
|
||||
if (options.hint) |hint| opts_obj.put(globalObject, jsc.ZigString.static("hint"), jsc.ZigString.init(hint).toJS(globalObject));
|
||||
if (options.severity) |severity| opts_obj.put(globalObject, jsc.ZigString.static("severity"), jsc.ZigString.init(severity).toJS(globalObject));
|
||||
if (options.position) |pos| opts_obj.put(globalObject, jsc.ZigString.static("position"), jsc.ZigString.init(pos).toJS(globalObject));
|
||||
if (options.internalPosition) |pos| opts_obj.put(globalObject, jsc.ZigString.static("internalPosition"), jsc.ZigString.init(pos).toJS(globalObject));
|
||||
if (options.internalQuery) |query| opts_obj.put(globalObject, jsc.ZigString.static("internalQuery"), jsc.ZigString.init(query).toJS(globalObject));
|
||||
if (options.where) |w| opts_obj.put(globalObject, jsc.ZigString.static("where"), jsc.ZigString.init(w).toJS(globalObject));
|
||||
if (options.schema) |s| opts_obj.put(globalObject, jsc.ZigString.static("schema"), jsc.ZigString.init(s).toJS(globalObject));
|
||||
if (options.table) |t| opts_obj.put(globalObject, jsc.ZigString.static("table"), jsc.ZigString.init(t).toJS(globalObject));
|
||||
if (options.column) |c| opts_obj.put(globalObject, jsc.ZigString.static("column"), jsc.ZigString.init(c).toJS(globalObject));
|
||||
if (options.dataType) |dt| opts_obj.put(globalObject, jsc.ZigString.static("dataType"), jsc.ZigString.init(dt).toJS(globalObject));
|
||||
if (options.constraint) |c| opts_obj.put(globalObject, jsc.ZigString.static("constraint"), jsc.ZigString.init(c).toJS(globalObject));
|
||||
if (options.file) |f| opts_obj.put(globalObject, jsc.ZigString.static("file"), jsc.ZigString.init(f).toJS(globalObject));
|
||||
if (options.line) |l| opts_obj.put(globalObject, jsc.ZigString.static("line"), jsc.ZigString.init(l).toJS(globalObject));
|
||||
if (options.routine) |r| opts_obj.put(globalObject, jsc.ZigString.static("routine"), jsc.ZigString.init(r).toJS(globalObject));
|
||||
|
||||
const args = [_]JSValue{
|
||||
jsc.ZigString.init(message).toJS(globalObject),
|
||||
opts_obj,
|
||||
};
|
||||
|
||||
const JSC = @import("../../bun.js/javascript_core_c_api.zig");
|
||||
var exception: JSC.JSValueRef = null;
|
||||
const result = JSC.JSObjectCallAsConstructor(globalObject, pg_error_constructor.asObjectRef(), args.len, @ptrCast(&args), &exception);
|
||||
|
||||
if (exception != null) {
|
||||
return bun.JSError.JSError;
|
||||
const opts_obj = JSValue.createEmptyObject(globalObject, 18);
|
||||
opts_obj.ensureStillAlive();
|
||||
opts_obj.put(globalObject, jsc.ZigString.static("code"), try bun.String.createUTF8ForJS(globalObject, options.code));
|
||||
inline for (std.meta.fields(PostgresErrorOptions)) |field| {
|
||||
const FieldType = @typeInfo(@TypeOf(@field(options, field.name)));
|
||||
if (FieldType == .optional) {
|
||||
if (@field(options, field.name)) |value| {
|
||||
opts_obj.put(globalObject, jsc.ZigString.static(field.name), try bun.String.createUTF8ForJS(globalObject, value));
|
||||
}
|
||||
}
|
||||
}
|
||||
opts_obj.put(globalObject, jsc.ZigString.static("message"), try bun.String.createUTF8ForJS(globalObject, message));
|
||||
|
||||
return JSValue.fromRef(result);
|
||||
return opts_obj;
|
||||
}
|
||||
|
||||
pub fn postgresErrorToJS(globalObject: *jsc.JSGlobalObject, message: ?[]const u8, err: AnyPostgresError) JSValue {
|
||||
@@ -142,10 +118,8 @@ pub fn postgresErrorToJS(globalObject: *jsc.JSGlobalObject, message: ?[]const u8
|
||||
},
|
||||
};
|
||||
|
||||
const msg = message orelse std.fmt.allocPrint(bun.default_allocator, "Failed to bind query: {s}", .{@errorName(err)}) catch unreachable;
|
||||
defer {
|
||||
if (message == null) bun.default_allocator.free(msg);
|
||||
}
|
||||
var buffer_message = [_]u8{0} ** 256;
|
||||
const msg = message orelse std.fmt.bufPrint(buffer_message[0..], "Failed to bind query: {s}", .{@errorName(err)}) catch "Failed to bind query";
|
||||
|
||||
return createPostgresError(globalObject, msg, .{ .code = code }) catch |e| globalObject.takeError(e);
|
||||
}
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
pub const ConnectionFlags = packed struct {
|
||||
is_ready_for_query: bool = false,
|
||||
is_processing_data: bool = false,
|
||||
use_unnamed_prepared_statements: bool = false,
|
||||
waiting_to_prepare: bool = false,
|
||||
has_backpressure: bool = false,
|
||||
};
|
||||
@@ -1,65 +0,0 @@
|
||||
pub const Data = union(enum) {
|
||||
owned: bun.ByteList,
|
||||
temporary: []const u8,
|
||||
empty: void,
|
||||
|
||||
pub const Empty: Data = .{ .empty = {} };
|
||||
|
||||
pub fn toOwned(this: @This()) !bun.ByteList {
|
||||
return switch (this) {
|
||||
.owned => this.owned,
|
||||
.temporary => bun.ByteList.init(try bun.default_allocator.dupe(u8, this.temporary)),
|
||||
.empty => bun.ByteList.init(&.{}),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn deinit(this: *@This()) void {
|
||||
switch (this.*) {
|
||||
.owned => this.owned.deinitWithAllocator(bun.default_allocator),
|
||||
.temporary => {},
|
||||
.empty => {},
|
||||
}
|
||||
}
|
||||
|
||||
/// Zero bytes before deinit
|
||||
/// Generally, for security reasons.
|
||||
pub fn zdeinit(this: *@This()) void {
|
||||
switch (this.*) {
|
||||
.owned => {
|
||||
|
||||
// Zero bytes before deinit
|
||||
@memset(this.owned.slice(), 0);
|
||||
|
||||
this.owned.deinitWithAllocator(bun.default_allocator);
|
||||
},
|
||||
.temporary => {},
|
||||
.empty => {},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn slice(this: @This()) []const u8 {
|
||||
return switch (this) {
|
||||
.owned => this.owned.slice(),
|
||||
.temporary => this.temporary,
|
||||
.empty => "",
|
||||
};
|
||||
}
|
||||
|
||||
pub fn substring(this: @This(), start_index: usize, end_index: usize) Data {
|
||||
return switch (this) {
|
||||
.owned => .{ .temporary = this.owned.slice()[start_index..end_index] },
|
||||
.temporary => .{ .temporary = this.temporary[start_index..end_index] },
|
||||
.empty => .{ .empty = {} },
|
||||
};
|
||||
}
|
||||
|
||||
pub fn sliceZ(this: @This()) [:0]const u8 {
|
||||
return switch (this) {
|
||||
.owned => this.owned.slice()[0..this.owned.len :0],
|
||||
.temporary => this.temporary[0..this.temporary.len :0],
|
||||
.empty => "",
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
const bun = @import("bun");
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,63 +0,0 @@
|
||||
const ObjectIterator = @This();
|
||||
|
||||
array: JSValue,
|
||||
columns: JSValue = .zero,
|
||||
globalObject: *jsc.JSGlobalObject,
|
||||
cell_i: usize = 0,
|
||||
row_i: usize = 0,
|
||||
current_row: jsc.JSValue = .zero,
|
||||
columns_count: usize = 0,
|
||||
array_length: usize = 0,
|
||||
any_failed: bool = false,
|
||||
|
||||
pub fn next(this: *ObjectIterator) ?jsc.JSValue {
|
||||
if (this.row_i >= this.array_length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const cell_i = this.cell_i;
|
||||
this.cell_i += 1;
|
||||
const row_i = this.row_i;
|
||||
|
||||
const globalObject = this.globalObject;
|
||||
|
||||
if (this.current_row == .zero) {
|
||||
this.current_row = jsc.JSObject.getIndex(this.array, globalObject, @intCast(row_i)) catch {
|
||||
this.any_failed = true;
|
||||
return null;
|
||||
};
|
||||
if (this.current_row.isEmptyOrUndefinedOrNull()) {
|
||||
return globalObject.throw("Expected a row to be returned at index {d}", .{row_i}) catch null;
|
||||
}
|
||||
}
|
||||
|
||||
defer {
|
||||
if (this.cell_i >= this.columns_count) {
|
||||
this.cell_i = 0;
|
||||
this.current_row = .zero;
|
||||
this.row_i += 1;
|
||||
}
|
||||
}
|
||||
|
||||
const property = jsc.JSObject.getIndex(this.columns, globalObject, @intCast(cell_i)) catch {
|
||||
this.any_failed = true;
|
||||
return null;
|
||||
};
|
||||
if (property.isUndefined()) {
|
||||
return globalObject.throw("Expected a column at index {d} in row {d}", .{ cell_i, row_i }) catch null;
|
||||
}
|
||||
|
||||
const value = this.current_row.getOwnByValue(globalObject, property);
|
||||
if (value == .zero or (value != null and value.?.isUndefined())) {
|
||||
if (!globalObject.hasException())
|
||||
return globalObject.throw("Expected a value at index {d} in row {d}", .{ cell_i, row_i }) catch null;
|
||||
this.any_failed = true;
|
||||
return null;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
const bun = @import("bun");
|
||||
|
||||
const jsc = bun.jsc;
|
||||
const JSValue = jsc.JSValue;
|
||||
@@ -1,32 +0,0 @@
|
||||
structure: jsc.Strong.Optional = .empty,
|
||||
// only populated if more than jsc.JSC__JSObject__maxInlineCapacity fields otherwise the structure will contain all fields inlined
|
||||
fields: ?[]jsc.JSObject.ExternColumnIdentifier = null,
|
||||
|
||||
pub fn has(this: *@This()) bool {
|
||||
return this.structure.has() or this.fields != null;
|
||||
}
|
||||
|
||||
pub fn jsValue(this: *const @This()) ?jsc.JSValue {
|
||||
return this.structure.get();
|
||||
}
|
||||
|
||||
pub fn set(this: *@This(), globalObject: *jsc.JSGlobalObject, value: ?jsc.JSValue, fields: ?[]jsc.JSObject.ExternColumnIdentifier) void {
|
||||
if (value) |v| {
|
||||
this.structure.set(globalObject, v);
|
||||
}
|
||||
this.fields = fields;
|
||||
}
|
||||
|
||||
pub fn deinit(this: *@This()) void {
|
||||
this.structure.deinit();
|
||||
if (this.fields) |fields| {
|
||||
this.fields = null;
|
||||
for (fields) |*name| {
|
||||
name.deinit();
|
||||
}
|
||||
bun.default_allocator.free(fields);
|
||||
}
|
||||
}
|
||||
|
||||
const bun = @import("bun");
|
||||
const jsc = bun.jsc;
|
||||
@@ -45,7 +45,7 @@ pub const SASLResponse = @import("./protocol/SASLResponse.zig");
|
||||
pub const StackReader = @import("./protocol/StackReader.zig");
|
||||
pub const StartupMessage = @import("./protocol/StartupMessage.zig");
|
||||
pub const Authentication = @import("./protocol/Authentication.zig").Authentication;
|
||||
pub const ColumnIdentifier = @import("./protocol/ColumnIdentifier.zig").ColumnIdentifier;
|
||||
pub const ColumnIdentifier = @import("../shared/ColumnIdentifier.zig").ColumnIdentifier;
|
||||
pub const DecoderWrap = @import("./protocol/DecoderWrap.zig").DecoderWrap;
|
||||
pub const FieldMessage = @import("./protocol/FieldMessage.zig").FieldMessage;
|
||||
pub const FieldType = @import("./protocol/FieldType.zig").FieldType;
|
||||
|
||||
@@ -332,7 +332,7 @@ const PostgresSQLStatement = @import("./PostgresSQLStatement.zig");
|
||||
const Signature = @import("./Signature.zig");
|
||||
const protocol = @import("./PostgresProtocol.zig");
|
||||
const std = @import("std");
|
||||
const QueryBindingIterator = @import("./QueryBindingIterator.zig").QueryBindingIterator;
|
||||
const QueryBindingIterator = @import("../shared/QueryBindingIterator.zig").QueryBindingIterator;
|
||||
|
||||
const types = @import("./PostgresTypes.zig");
|
||||
const AnyPostgresError = @import("./PostgresTypes.zig").AnyPostgresError;
|
||||
|
||||
@@ -311,7 +311,7 @@ pub fn failWithJSValue(this: *PostgresSQLConnection, value: JSValue) void {
|
||||
this.stopTimers();
|
||||
if (this.status == .failed) return;
|
||||
|
||||
this.status = .failed;
|
||||
this.setStatus(.failed);
|
||||
|
||||
this.ref();
|
||||
defer this.deref();
|
||||
@@ -584,7 +584,7 @@ comptime {
|
||||
|
||||
pub fn call(globalObject: *jsc.JSGlobalObject, callframe: *jsc.CallFrame) bun.JSError!jsc.JSValue {
|
||||
var vm = globalObject.bunVM();
|
||||
const arguments = callframe.arguments_old(15).slice();
|
||||
const arguments = callframe.arguments();
|
||||
const hostname_str = try arguments[0].toBunString(globalObject);
|
||||
defer hostname_str.deref();
|
||||
const port = try arguments[1].coerce(i32, globalObject);
|
||||
@@ -700,7 +700,7 @@ pub fn call(globalObject: *jsc.JSGlobalObject, callframe: *jsc.CallFrame) bun.JS
|
||||
|
||||
ptr.* = PostgresSQLConnection{
|
||||
.globalObject = globalObject,
|
||||
.vm = globalObject.bunVM(),
|
||||
.vm = vm,
|
||||
.database = database,
|
||||
.user = username,
|
||||
.password = password,
|
||||
@@ -1157,7 +1157,9 @@ fn advance(this: *PostgresSQLConnection) void {
|
||||
} else {
|
||||
// deinit later
|
||||
req.status = .fail;
|
||||
offset += 1;
|
||||
}
|
||||
|
||||
continue;
|
||||
},
|
||||
.prepared => {
|
||||
@@ -1185,9 +1187,9 @@ fn advance(this: *PostgresSQLConnection) void {
|
||||
} else {
|
||||
// deinit later
|
||||
req.status = .fail;
|
||||
offset += 1;
|
||||
}
|
||||
debug("bind and execute failed: {s}", .{@errorName(err)});
|
||||
|
||||
continue;
|
||||
};
|
||||
|
||||
@@ -1356,8 +1358,8 @@ pub fn on(this: *PostgresSQLConnection, comptime MessageType: @Type(.enum_litera
|
||||
.globalObject = this.globalObject,
|
||||
};
|
||||
|
||||
var stack_buf: [70]DataCell = undefined;
|
||||
var cells: []DataCell = stack_buf[0..@min(statement.fields.len, jsc.JSObject.maxInlineCapacity())];
|
||||
var stack_buf: [70]DataCell.SQLDataCell = undefined;
|
||||
var cells: []DataCell.SQLDataCell = stack_buf[0..@min(statement.fields.len, jsc.JSObject.maxInlineCapacity())];
|
||||
var free_cells = false;
|
||||
defer {
|
||||
for (cells[0..putter.count]) |*cell| {
|
||||
@@ -1367,11 +1369,11 @@ pub fn on(this: *PostgresSQLConnection, comptime MessageType: @Type(.enum_litera
|
||||
}
|
||||
|
||||
if (statement.fields.len >= jsc.JSObject.maxInlineCapacity()) {
|
||||
cells = try bun.default_allocator.alloc(DataCell, statement.fields.len);
|
||||
cells = try bun.default_allocator.alloc(DataCell.SQLDataCell, statement.fields.len);
|
||||
free_cells = true;
|
||||
}
|
||||
// make sure all cells are reset if reader short breaks the fields will just be null with is better than undefined behavior
|
||||
@memset(cells, DataCell{ .tag = .null, .value = .{ .null = 0 } });
|
||||
@memset(cells, DataCell.SQLDataCell{ .tag = .null, .value = .{ .null = 0 } });
|
||||
putter.list = cells;
|
||||
|
||||
if (request.flags.result_mode == .raw) {
|
||||
@@ -1395,7 +1397,14 @@ pub fn on(this: *PostgresSQLConnection, comptime MessageType: @Type(.enum_litera
|
||||
};
|
||||
const pending_value = PostgresSQLQuery.js.pendingValueGetCached(thisValue) orelse .zero;
|
||||
pending_value.ensureStillAlive();
|
||||
const result = putter.toJS(this.globalObject, pending_value, structure, statement.fields_flags, request.flags.result_mode, cached_structure);
|
||||
const result = putter.toJS(
|
||||
this.globalObject,
|
||||
pending_value,
|
||||
structure,
|
||||
statement.fields_flags,
|
||||
request.flags.result_mode,
|
||||
cached_structure,
|
||||
);
|
||||
|
||||
if (pending_value == .zero) {
|
||||
PostgresSQLQuery.js.pendingValueSetCached(thisValue, this.globalObject, result);
|
||||
@@ -1814,7 +1823,8 @@ pub const fromJS = js.fromJS;
|
||||
pub const fromJSDirect = js.fromJSDirect;
|
||||
pub const toJS = js.toJS;
|
||||
|
||||
const PostgresCachedStructure = @import("./PostgresCachedStructure.zig");
|
||||
const DataCell = @import("./DataCell.zig");
|
||||
const PostgresCachedStructure = @import("../shared/CachedStructure.zig");
|
||||
const PostgresRequest = @import("./PostgresRequest.zig");
|
||||
const PostgresSQLQuery = @import("./PostgresSQLQuery.zig");
|
||||
const PostgresSQLStatement = @import("./PostgresSQLStatement.zig");
|
||||
@@ -1822,9 +1832,8 @@ const SocketMonitor = @import("./SocketMonitor.zig");
|
||||
const protocol = @import("./PostgresProtocol.zig");
|
||||
const std = @import("std");
|
||||
const AuthenticationState = @import("./AuthenticationState.zig").AuthenticationState;
|
||||
const ConnectionFlags = @import("./ConnectionFlags.zig").ConnectionFlags;
|
||||
const Data = @import("./Data.zig").Data;
|
||||
const DataCell = @import("./DataCell.zig").DataCell;
|
||||
const ConnectionFlags = @import("../shared/ConnectionFlags.zig").ConnectionFlags;
|
||||
const Data = @import("../shared/Data.zig").Data;
|
||||
const SSLMode = @import("./SSLMode.zig").SSLMode;
|
||||
const Status = @import("./Status.zig").Status;
|
||||
const TLSStatus = @import("./TLSStatus.zig").TLSStatus;
|
||||
|
||||
@@ -186,7 +186,7 @@ pub fn estimatedSize(this: *PostgresSQLQuery) usize {
|
||||
}
|
||||
|
||||
pub fn call(globalThis: *jsc.JSGlobalObject, callframe: *jsc.CallFrame) bun.JSError!jsc.JSValue {
|
||||
const arguments = callframe.arguments_old(6).slice();
|
||||
const arguments = callframe.arguments();
|
||||
var args = jsc.CallFrame.ArgumentsSlice.init(globalThis.bunVM(), arguments);
|
||||
defer args.deinit();
|
||||
const query = args.nextEat() orelse {
|
||||
@@ -276,8 +276,7 @@ pub fn setMode(this: *PostgresSQLQuery, globalObject: *jsc.JSGlobalObject, callf
|
||||
}
|
||||
|
||||
pub fn doRun(this: *PostgresSQLQuery, globalObject: *jsc.JSGlobalObject, callframe: *jsc.CallFrame) bun.JSError!JSValue {
|
||||
var arguments_ = callframe.arguments_old(2);
|
||||
const arguments = arguments_.slice();
|
||||
var arguments = callframe.arguments();
|
||||
const connection: *PostgresSQLConnection = arguments[0].as(PostgresSQLConnection) orelse {
|
||||
return globalObject.throw("connection must be a PostgresSQLConnection", .{});
|
||||
};
|
||||
@@ -375,11 +374,10 @@ pub fn doRun(this: *PostgresSQLQuery, globalObject: *jsc.JSGlobalObject, callfra
|
||||
switch (stmt.status) {
|
||||
.failed => {
|
||||
this.statement = null;
|
||||
const error_response = try stmt.error_response.?.toJS(globalObject);
|
||||
stmt.deref();
|
||||
this.deref();
|
||||
// If the statement failed, we need to throw the error
|
||||
const e = try this.statement.?.error_response.?.toJS(globalObject);
|
||||
return globalObject.throwValue(e);
|
||||
return globalObject.throwValue(error_response);
|
||||
},
|
||||
.prepared => {
|
||||
if (!connection.hasQueryRunning() or connection.canPipeline()) {
|
||||
@@ -524,7 +522,7 @@ const bun = @import("bun");
|
||||
const protocol = @import("./PostgresProtocol.zig");
|
||||
const std = @import("std");
|
||||
const CommandTag = @import("./CommandTag.zig").CommandTag;
|
||||
const PostgresSQLQueryResultMode = @import("./PostgresSQLQueryResultMode.zig").PostgresSQLQueryResultMode;
|
||||
const PostgresSQLQueryResultMode = @import("../shared/SQLQueryResultMode.zig").SQLQueryResultMode;
|
||||
|
||||
const AnyPostgresError = @import("./AnyPostgresError.zig").AnyPostgresError;
|
||||
const postgresErrorToJS = @import("./AnyPostgresError.zig").postgresErrorToJS;
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
pub const PostgresSQLQueryResultMode = enum(u2) {
|
||||
objects = 0,
|
||||
values = 1,
|
||||
raw = 2,
|
||||
};
|
||||
@@ -162,11 +162,11 @@ pub fn structure(this: *PostgresSQLStatement, owner: JSValue, globalObject: *jsc
|
||||
|
||||
const debug = bun.Output.scoped(.Postgres, .visible);
|
||||
|
||||
const PostgresCachedStructure = @import("./PostgresCachedStructure.zig");
|
||||
const PostgresCachedStructure = @import("../shared/CachedStructure.zig");
|
||||
const Signature = @import("./Signature.zig");
|
||||
const protocol = @import("./PostgresProtocol.zig");
|
||||
const std = @import("std");
|
||||
const DataCell = @import("./DataCell.zig").DataCell;
|
||||
const DataCell = @import("./DataCell.zig").SQLDataCell;
|
||||
|
||||
const AnyPostgresError = @import("./AnyPostgresError.zig").AnyPostgresError;
|
||||
const postgresErrorToJS = @import("./AnyPostgresError.zig").postgresErrorToJS;
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
pub const QueryBindingIterator = union(enum) {
|
||||
array: jsc.JSArrayIterator,
|
||||
objects: ObjectIterator,
|
||||
|
||||
pub fn init(array: JSValue, columns: JSValue, globalObject: *jsc.JSGlobalObject) bun.JSError!QueryBindingIterator {
|
||||
if (columns.isEmptyOrUndefinedOrNull()) {
|
||||
return .{ .array = try jsc.JSArrayIterator.init(array, globalObject) };
|
||||
}
|
||||
|
||||
return .{
|
||||
.objects = .{
|
||||
.array = array,
|
||||
.columns = columns,
|
||||
.globalObject = globalObject,
|
||||
.columns_count = try columns.getLength(globalObject),
|
||||
.array_length = try array.getLength(globalObject),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
pub fn next(this: *QueryBindingIterator) bun.JSError!?jsc.JSValue {
|
||||
return switch (this.*) {
|
||||
.array => |*iter| iter.next(),
|
||||
.objects => |*iter| iter.next(),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn anyFailed(this: *const QueryBindingIterator) bool {
|
||||
return switch (this.*) {
|
||||
.array => false,
|
||||
.objects => |*iter| iter.any_failed,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn to(this: *QueryBindingIterator, index: u32) void {
|
||||
switch (this.*) {
|
||||
.array => |*iter| iter.i = index,
|
||||
.objects => |*iter| {
|
||||
iter.cell_i = index % iter.columns_count;
|
||||
iter.row_i = index / iter.columns_count;
|
||||
iter.current_row = .zero;
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn reset(this: *QueryBindingIterator) void {
|
||||
switch (this.*) {
|
||||
.array => |*iter| {
|
||||
iter.i = 0;
|
||||
},
|
||||
.objects => |*iter| {
|
||||
iter.cell_i = 0;
|
||||
iter.row_i = 0;
|
||||
iter.current_row = .zero;
|
||||
},
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const ObjectIterator = @import("./ObjectIterator.zig");
|
||||
const bun = @import("bun");
|
||||
|
||||
const jsc = bun.jsc;
|
||||
const JSValue = jsc.JSValue;
|
||||
@@ -103,7 +103,7 @@ pub fn generate(globalObject: *jsc.JSGlobalObject, query: []const u8, array_valu
|
||||
|
||||
const bun = @import("bun");
|
||||
const std = @import("std");
|
||||
const QueryBindingIterator = @import("./QueryBindingIterator.zig").QueryBindingIterator;
|
||||
const QueryBindingIterator = @import("../shared/QueryBindingIterator.zig").QueryBindingIterator;
|
||||
|
||||
const types = @import("./PostgresTypes.zig");
|
||||
const int4 = types.int4;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
pub fn write(data: []const u8) void {
|
||||
debug("SocketMonitor: write {s}", .{std.fmt.fmtSliceHexLower(data)});
|
||||
if (comptime bun.Environment.isDebug) {
|
||||
DebugSocketMonitorWriter.check.call();
|
||||
if (DebugSocketMonitorWriter.enabled) {
|
||||
@@ -8,6 +9,7 @@ pub fn write(data: []const u8) void {
|
||||
}
|
||||
|
||||
pub fn read(data: []const u8) void {
|
||||
debug("SocketMonitor: read {s}", .{std.fmt.fmtSliceHexLower(data)});
|
||||
if (comptime bun.Environment.isDebug) {
|
||||
DebugSocketMonitorReader.check.call();
|
||||
if (DebugSocketMonitorReader.enabled) {
|
||||
@@ -16,6 +18,9 @@ pub fn read(data: []const u8) void {
|
||||
}
|
||||
}
|
||||
|
||||
const debug = bun.Output.scoped(.SocketMonitor, .visible);
|
||||
|
||||
const DebugSocketMonitorReader = @import("./DebugSocketMonitorReader.zig");
|
||||
const DebugSocketMonitorWriter = @import("./DebugSocketMonitorWriter.zig");
|
||||
const bun = @import("bun");
|
||||
const std = @import("std");
|
||||
|
||||
@@ -175,6 +175,6 @@ const debug = bun.Output.scoped(.Postgres, .hidden);
|
||||
|
||||
const bun = @import("bun");
|
||||
const std = @import("std");
|
||||
const Data = @import("../Data.zig").Data;
|
||||
const Data = @import("../../shared/Data.zig").Data;
|
||||
const DecoderWrap = @import("./DecoderWrap.zig").DecoderWrap;
|
||||
const NewReader = @import("./NewReader.zig").NewReader;
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
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("../Data.zig").Data;
|
||||
@@ -19,6 +19,6 @@ pub fn decodeInternal(this: *@This(), comptime Container: type, reader: NewReade
|
||||
pub const decode = DecoderWrap(CommandComplete, decodeInternal).decode;
|
||||
|
||||
const bun = @import("bun");
|
||||
const Data = @import("../Data.zig").Data;
|
||||
const Data = @import("../../shared/Data.zig").Data;
|
||||
const DecoderWrap = @import("./DecoderWrap.zig").DecoderWrap;
|
||||
const NewReader = @import("./NewReader.zig").NewReader;
|
||||
|
||||
@@ -30,7 +30,7 @@ pub fn writeInternal(
|
||||
pub const write = WriteWrap(@This(), writeInternal).write;
|
||||
|
||||
const std = @import("std");
|
||||
const Data = @import("../Data.zig").Data;
|
||||
const Data = @import("../../shared/Data.zig").Data;
|
||||
const DecoderWrap = @import("./DecoderWrap.zig").DecoderWrap;
|
||||
const Int32 = @import("../types/int_types.zig").Int32;
|
||||
const NewReader = @import("./NewReader.zig").NewReader;
|
||||
|
||||
@@ -30,7 +30,7 @@ pub fn writeInternal(
|
||||
pub const write = WriteWrap(@This(), writeInternal).write;
|
||||
|
||||
const std = @import("std");
|
||||
const Data = @import("../Data.zig").Data;
|
||||
const Data = @import("../../shared/Data.zig").Data;
|
||||
const DecoderWrap = @import("./DecoderWrap.zig").DecoderWrap;
|
||||
const NewReader = @import("./NewReader.zig").NewReader;
|
||||
const NewWriter = @import("./NewWriter.zig").NewWriter;
|
||||
|
||||
@@ -24,8 +24,8 @@ pub fn decode(context: anytype, comptime ContextType: type, reader: NewReader(Co
|
||||
|
||||
pub const null_int4 = 4294967295;
|
||||
|
||||
const Data = @import("../../shared/Data.zig").Data;
|
||||
|
||||
const AnyPostgresError = @import("../AnyPostgresError.zig").AnyPostgresError;
|
||||
|
||||
const Data = @import("../Data.zig").Data;
|
||||
|
||||
const NewReader = @import("./NewReader.zig").NewReader;
|
||||
|
||||
@@ -60,7 +60,7 @@ pub fn decodeInternal(this: *@This(), comptime Container: type, reader: NewReade
|
||||
pub const decode = DecoderWrap(FieldDescription, decodeInternal).decode;
|
||||
|
||||
const AnyPostgresError = @import("../AnyPostgresError.zig").AnyPostgresError;
|
||||
const ColumnIdentifier = @import("./ColumnIdentifier.zig").ColumnIdentifier;
|
||||
const ColumnIdentifier = @import("../../shared/ColumnIdentifier.zig").ColumnIdentifier;
|
||||
const DecoderWrap = @import("./DecoderWrap.zig").DecoderWrap;
|
||||
const NewReader = @import("./NewReader.zig").NewReader;
|
||||
|
||||
|
||||
@@ -113,7 +113,7 @@ pub fn NewReader(comptime Context: type) type {
|
||||
|
||||
const bun = @import("bun");
|
||||
const AnyPostgresError = @import("../AnyPostgresError.zig").AnyPostgresError;
|
||||
const Data = @import("../Data.zig").Data;
|
||||
const Data = @import("../../shared/Data.zig").Data;
|
||||
|
||||
const int_types = @import("../types/int_types.zig");
|
||||
const PostgresInt32 = int_types.PostgresInt32;
|
||||
|
||||
@@ -21,6 +21,6 @@ pub fn decodeInternal(this: *@This(), comptime Container: type, reader: NewReade
|
||||
pub const decode = DecoderWrap(ParameterStatus, decodeInternal).decode;
|
||||
|
||||
const bun = @import("bun");
|
||||
const Data = @import("../Data.zig").Data;
|
||||
const Data = @import("../../shared/Data.zig").Data;
|
||||
const DecoderWrap = @import("./DecoderWrap.zig").DecoderWrap;
|
||||
const NewReader = @import("./NewReader.zig").NewReader;
|
||||
|
||||
@@ -23,7 +23,7 @@ pub fn writeInternal(
|
||||
pub const write = WriteWrap(@This(), writeInternal).write;
|
||||
|
||||
const std = @import("std");
|
||||
const Data = @import("../Data.zig").Data;
|
||||
const Data = @import("../../shared/Data.zig").Data;
|
||||
const Int32 = @import("../types/int_types.zig").Int32;
|
||||
const NewWriter = @import("./NewWriter.zig").NewWriter;
|
||||
const WriteWrap = @import("./WriteWrap.zig").WriteWrap;
|
||||
|
||||
@@ -28,7 +28,7 @@ pub fn writeInternal(
|
||||
pub const write = WriteWrap(@This(), writeInternal).write;
|
||||
|
||||
const std = @import("std");
|
||||
const Data = @import("../Data.zig").Data;
|
||||
const Data = @import("../../shared/Data.zig").Data;
|
||||
const Int32 = @import("../types/int_types.zig").Int32;
|
||||
const NewWriter = @import("./NewWriter.zig").NewWriter;
|
||||
const WriteWrap = @import("./WriteWrap.zig").WriteWrap;
|
||||
|
||||
@@ -23,7 +23,7 @@ pub fn writeInternal(
|
||||
pub const write = WriteWrap(@This(), writeInternal).write;
|
||||
|
||||
const std = @import("std");
|
||||
const Data = @import("../Data.zig").Data;
|
||||
const Data = @import("../../shared/Data.zig").Data;
|
||||
const Int32 = @import("../types/int_types.zig").Int32;
|
||||
const NewWriter = @import("./NewWriter.zig").NewWriter;
|
||||
const WriteWrap = @import("./WriteWrap.zig").WriteWrap;
|
||||
|
||||
@@ -61,5 +61,5 @@ pub fn readZ(this: StackReader) AnyPostgresError!Data {
|
||||
|
||||
const bun = @import("bun");
|
||||
const AnyPostgresError = @import("../AnyPostgresError.zig").AnyPostgresError;
|
||||
const Data = @import("../Data.zig").Data;
|
||||
const Data = @import("../../shared/Data.zig").Data;
|
||||
const NewReader = @import("./NewReader.zig").NewReader;
|
||||
|
||||
@@ -39,7 +39,7 @@ pub fn writeInternal(
|
||||
pub const write = WriteWrap(@This(), writeInternal).write;
|
||||
|
||||
const std = @import("std");
|
||||
const Data = @import("../Data.zig").Data;
|
||||
const Data = @import("../../shared/Data.zig").Data;
|
||||
const NewWriter = @import("./NewWriter.zig").NewWriter;
|
||||
const WriteWrap = @import("./WriteWrap.zig").WriteWrap;
|
||||
const zFieldCount = @import("./zHelpers.zig").zFieldCount;
|
||||
|
||||
@@ -41,7 +41,7 @@ pub fn toJS(
|
||||
|
||||
const bun = @import("bun");
|
||||
const AnyPostgresError = @import("../AnyPostgresError.zig").AnyPostgresError;
|
||||
const Data = @import("../Data.zig").Data;
|
||||
const Data = @import("../../shared/Data.zig").Data;
|
||||
|
||||
const int_types = @import("./int_types.zig");
|
||||
const short = int_types.short;
|
||||
|
||||
@@ -14,7 +14,7 @@ pub fn toJS(
|
||||
|
||||
const bun = @import("bun");
|
||||
const AnyPostgresError = @import("../AnyPostgresError.zig").AnyPostgresError;
|
||||
const Data = @import("../Data.zig").Data;
|
||||
const Data = @import("../../shared/Data.zig").Data;
|
||||
|
||||
const int_types = @import("./int_types.zig");
|
||||
const short = int_types.short;
|
||||
|
||||
@@ -46,7 +46,7 @@ pub fn toJS(
|
||||
|
||||
const bun = @import("bun");
|
||||
const std = @import("std");
|
||||
const Data = @import("../Data.zig").Data;
|
||||
const Data = @import("../../shared/Data.zig").Data;
|
||||
|
||||
const int_types = @import("./int_types.zig");
|
||||
const short = int_types.short;
|
||||
|
||||
@@ -18,7 +18,7 @@ pub fn toJS(
|
||||
|
||||
const bun = @import("bun");
|
||||
const AnyPostgresError = @import("../AnyPostgresError.zig").AnyPostgresError;
|
||||
const Data = @import("../Data.zig").Data;
|
||||
const Data = @import("../../shared/Data.zig").Data;
|
||||
|
||||
const int_types = @import("./int_types.zig");
|
||||
const short = int_types.short;
|
||||
|
||||
Reference in New Issue
Block a user