diff --git a/src/bun.js/bindings/SQLClient.cpp b/src/bun.js/bindings/SQLClient.cpp index c9c8f41313..8e1bc5adc6 100644 --- a/src/bun.js/bindings/SQLClient.cpp +++ b/src/bun.js/bindings/SQLClient.cpp @@ -441,13 +441,19 @@ extern "C" EncodedJSValue JSC__createStructure(JSC::JSGlobalObject* globalObject if (name.isNamedColumn()) { propertyNames.add(Identifier::fromString(vm, name.name.toWTFString())); } + if (name.isIndexedColumn()) { + return encodedJSValue(); + } + nonDuplicateCount += !name.isDuplicateColumn(); if (nonDuplicateCount == JSFinalObject::maxInlineCapacity) { break; } } - Structure* structure = globalObject->structureCache().emptyObjectStructureForPrototype(globalObject, globalObject->objectPrototype(), nonDuplicateCount); + ASSERT_WITH_MESSAGE(nonDuplicateCount < JSFinalObject::maxInlineCapacity, "expected nonDuplicateCount %u to be less than maxInlineCapacity %u", nonDuplicateCount, JSFinalObject::maxInlineCapacity); + Structure* structure = Structure::create(vm, globalObject, globalObject->objectPrototype(), JSFinalObject::typeInfo(), JSFinalObject::info(), NonArray, nonDuplicateCount); + if (owner) { vm.writeBarrier(owner, structure); } else { diff --git a/src/sql/mysql/MySQLConnection.zig b/src/sql/mysql/MySQLConnection.zig index 368fc03b7b..213d8d2510 100644 --- a/src/sql/mysql/MySQLConnection.zig +++ b/src/sql/mysql/MySQLConnection.zig @@ -1871,7 +1871,7 @@ pub fn handleResultSet(this: *MySQLConnection, comptime Context: type, reader: N .bigint = request.flags.bigint, }; var structure: JSValue = .js_undefined; - var cached_structure: ?CachedStructure = null; + var cached_structure: ?*CachedStructure = null; switch (request.flags.result_mode) { .objects => { cached_structure = statement.structure(this.js_value, this.globalObject); diff --git a/src/sql/mysql/MySQLStatement.zig b/src/sql/mysql/MySQLStatement.zig index 3933a2e63d..0348ac900b 100644 --- a/src/sql/mysql/MySQLStatement.zig +++ b/src/sql/mysql/MySQLStatement.zig @@ -103,9 +103,9 @@ pub fn checkForDuplicateFields(this: *@This()) void { this.fields_flags = flags; } -pub fn structure(this: *MySQLStatement, owner: JSValue, globalObject: *jsc.JSGlobalObject) CachedStructure { +pub fn structure(this: *MySQLStatement, owner: JSValue, globalObject: *jsc.JSGlobalObject) *CachedStructure { if (this.cached_structure.has()) { - return this.cached_structure; + return &this.cached_structure; } this.checkForDuplicateFields(); @@ -155,7 +155,7 @@ pub fn structure(this: *MySQLStatement, owner: JSValue, globalObject: *jsc.JSGlo ), null); } - return this.cached_structure; + return &this.cached_structure; } pub const Param = struct { type: types.FieldType, diff --git a/src/sql/mysql/protocol/ResultSet.zig b/src/sql/mysql/protocol/ResultSet.zig index d5a06d117f..92d2b9ddf0 100644 --- a/src/sql/mysql/protocol/ResultSet.zig +++ b/src/sql/mysql/protocol/ResultSet.zig @@ -8,7 +8,7 @@ pub const Row = struct { bigint: bool = false, globalObject: *jsc.JSGlobalObject, - pub fn toJS(this: *Row, globalObject: *jsc.JSGlobalObject, array: JSValue, structure: JSValue, flags: SQLDataCell.Flags, result_mode: SQLQueryResultMode, cached_structure: ?CachedStructure) JSValue { + pub fn toJS(this: *Row, globalObject: *jsc.JSGlobalObject, array: JSValue, structure: JSValue, flags: SQLDataCell.Flags, result_mode: SQLQueryResultMode, cached_structure: ?*const CachedStructure) JSValue { var names: ?[*]jsc.JSObject.ExternColumnIdentifier = null; var names_count: u32 = 0; if (cached_structure) |c| { diff --git a/src/sql/postgres/DataCell.zig b/src/sql/postgres/DataCell.zig index 4ca56895c0..0f7b55bfac 100644 --- a/src/sql/postgres/DataCell.zig +++ b/src/sql/postgres/DataCell.zig @@ -902,7 +902,7 @@ pub const Putter = struct { count: usize = 0, globalObject: *jsc.JSGlobalObject, - pub fn toJS(this: *Putter, globalObject: *jsc.JSGlobalObject, array: JSValue, structure: JSValue, flags: SQLDataCell.Flags, result_mode: PostgresSQLQueryResultMode, cached_structure: ?PostgresCachedStructure) JSValue { + pub fn toJS(this: *Putter, globalObject: *jsc.JSGlobalObject, array: JSValue, structure: JSValue, flags: SQLDataCell.Flags, result_mode: PostgresSQLQueryResultMode, cached_structure: ?*PostgresCachedStructure) JSValue { var names: ?[*]jsc.JSObject.ExternColumnIdentifier = null; var names_count: u32 = 0; if (cached_structure) |c| { diff --git a/src/sql/postgres/PostgresSQLConnection.zig b/src/sql/postgres/PostgresSQLConnection.zig index 01a5fba6bd..a8bf29a5ac 100644 --- a/src/sql/postgres/PostgresSQLConnection.zig +++ b/src/sql/postgres/PostgresSQLConnection.zig @@ -1362,7 +1362,7 @@ pub fn on(this: *PostgresSQLConnection, comptime MessageType: @Type(.enum_litera var statement = request.statement orelse return error.ExpectedStatement; var structure: JSValue = .js_undefined; - var cached_structure: ?PostgresCachedStructure = null; + var cached_structure: ?*PostgresCachedStructure = null; // explicit use switch without else so if new modes are added, we don't forget to check for duplicate fields switch (request.flags.result_mode) { .objects => { diff --git a/src/sql/postgres/PostgresSQLStatement.zig b/src/sql/postgres/PostgresSQLStatement.zig index adf57f0e59..a1f7108b7c 100644 --- a/src/sql/postgres/PostgresSQLStatement.zig +++ b/src/sql/postgres/PostgresSQLStatement.zig @@ -107,9 +107,9 @@ pub fn deinit(this: *PostgresSQLStatement) void { bun.default_allocator.destroy(this); } -pub fn structure(this: *PostgresSQLStatement, owner: JSValue, globalObject: *jsc.JSGlobalObject) PostgresCachedStructure { +pub fn structure(this: *PostgresSQLStatement, owner: JSValue, globalObject: *jsc.JSGlobalObject) *PostgresCachedStructure { if (this.cached_structure.has()) { - return this.cached_structure; + return &this.cached_structure; } this.checkForDuplicateFields(); @@ -157,7 +157,7 @@ pub fn structure(this: *PostgresSQLStatement, owner: JSValue, globalObject: *jsc ), null); } - return this.cached_structure; + return &this.cached_structure; } const debug = bun.Output.scoped(.Postgres, .visible);