postgres-nio icon indicating copy to clipboard operation
postgres-nio copied to clipboard

Allow introspection of Rows by making PostgresRow.lookupTable readable

Open winsmith opened this issue 3 years ago • 3 comments

Is your feature request related to a problem? Please describe. For a variety of complicated tasks, I want to use hand-crafted queries (instead of relying on Fluent's ORM). I run these queries and would like to convert them into an array to return them to my client.

To do this, however, I seem to need to know in advance how the row fields are named, since I can only access a row field by name. This is frustrating since I would like to use different row field names in different queries and still use the same code to convert them into a dictionary.

Describe the solution you'd like I almost got my solution from PostgresRow.description, which loops through self.lookupTable.rowDescription.fields to get the field names.

I tried to write an extension to PostgresRow that would give me the field names, but 'lookupTable' is inaccessible due to 'internal' protection level. So my request is to make the lookupTable property readable.

Describe alternatives you've considered The alternative I'm going with for now is to build a query and staple to it the list of expected field names and types. This seems a bit unwieldy, especially since the data is right there 😅

Thanks and stay awesome <3

winsmith avatar Nov 21 '20 14:11 winsmith

Can you not achieve this with raw sql kit queries or the sql builder? Or are you saying it should be built into fluent?

jonny7 avatar Nov 21 '20 18:11 jonny7

I'm saying if I build a raw SQL query, and get the result back, I don't know any easy solution to find out the column titles in the result. I mean, I kinda know because I wrote the query and defined the column titles there, but it would be helpful to read these out of the PostgresRow instance somehow.

winsmith avatar Nov 22 '20 11:11 winsmith

I see no reason not to make it public - it seems like a reasonable use case. @gwynne Any objections?

0xTim avatar Dec 12 '20 17:12 0xTim