-
Notifications
You must be signed in to change notification settings - Fork 66
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
base: master
Are you sure you want to change the base?
Conversation
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; | ||
} | ||
|
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
andasObjects
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 awithNames
method that will wrap it in an object interface with the names
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 😆 🙈
There was a problem hiding this comment.
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...
No description provided.