Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement proper array-like SQL record/row compatible with 6b1 #1156

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

1st1
Copy link
Member

@1st1 1st1 commented Dec 14, 2024

No description provided.

@1st1 1st1 requested review from scotttrinh and jaclarke December 14, 2024 06:14
Comment on lines +266 to +274
case CTYPE_RECORD: {
const els = frb.readUInt16();
for (let i = 0; i < els; i++) {
const elm_length = frb.readUInt32();
frb.discard(elm_length + 2);
}
break;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this code will ever actually get executed, since for protocol v2+ the type descriptors are length prefixed, so we skip the whole typedesc in one go (line 113).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, good point, I'll double check

result[i] = val;
}

return result;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we were going to decode sql records into some custom datatype where you could access columns by name or index?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pesonally fine with this being an array of tuples by default. If we had a custom datatype for this here are some options I've just thought of:

  • asTuples and asObjects methods to make it easy to serialize, but then we pay for the overhead of the custom datatype.
  • toJSON method that serializes as an array of tuples
  • wrap an array of tuples (and has the appropriate getter in the valueOf prototype method) and provide a withNames method that will wrap it in an object interface with the names

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought so too and then I started digging why we stopped doing custom data types for named tuples and found this: #310

tl;dr: we can do custom types but some JS frameworks hardcode their JSON serialization exclusively for Array / Object types and fail with anything that extends them or does anything funky

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I support just making this an array of tuples and worry about exposing a way of getting an array of objects as a separate effort.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I had forgot about the serialisation issues. Maybe this can be solved with the custom codecs api? We could default to decoding to arrays as it is now, but also provide a builtin 'custom' codec that would decode to objects with names, so users could choose?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

provide a builtin 'custom' codec that would decode to objects with names, so users could choose?

Oh, yes! This was my original idea, but I had forgotten that I had it 😆 🙈

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I thought about this too. It might be a slightly different special cased version of .withCodecs, because "SQL Record" doesn't really have a type name. Can be symbol though...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants