will / crystal-pg

a postgres driver for crystal

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support for fetching results in the text format

17dec opened this issue · comments

commented

I'm using crystal-pg to build a web-based query UI, which means I don't control the queries that are being executed nor which types are being used. Postgres does a much better job at formatting every possible type as text than we could ever hope to achieve, so I'd like to make use of that. My current approach involves running a COPY command (using #279) and parsing its output. While that has the benefit of letting me use the same format for caching query results, the downside is that dealing with TSV everywhere adds some extra overhead of its own, so I'm wondering if it isn't a better idea to grab the results the traditional way, but in the text format.

I'd be happy to write a PR for this, but I'm stuck on how to best expose this functionality through the API. Adjusting PG::Statement::perform_query to request the text format and ResultSet to handle this case and always offer a direct String read seems like an obvious approach, but how do we tell perform_query to switch to text? Add a flag to PG::Connection?

Is this a use case you're interested in supporting?