stablekernel / postgresql-dart

Dart PostgreSQL driver: supports extended query format, binary protocol and statement reuse.
https://www.dartdocs.org/documentation/postgres/latest
BSD 3-Clause "New" or "Revised" License
129 stars 32 forks source link

2.3.1 JSON no longer escaped. #157

Closed zambetpentru closed 2 months ago

zambetpentru commented 3 years ago

Hi,

I just upgraded to 2.3.1 and the following query no longer returns JSON escaped

Select array_to_json(array_agg(row_to_json(A))) from (SELECT tablekey, tablename, ClientKey, CreatedDate, tableID
FROM public.table
      ) A

Before with 2.3.0: [{"tablekey":1,"tablename":"Collection 1","clientkey":1,"createddate":"2020-02-05T00:00:00","tableID":"5f2134234q2342342324"}]

Now with 2.3.1: [{tablekey: 1, tablename: Collection 1, clientkey: 1, createddate: 2020-02-05T00:00:00, tableID: 5f2134234q2342342324}]

Have you any ideas if there's something I need to change on my end or is it a bug?

isoos commented 3 years ago

Please follow the repository/homepage url of the package, 2.3.1 is now published from a fork. It did have a change that has an effect on this behaviour: https://github.com/isoos/postgresql-dart/pull/3

I'm not sure if the new behaviour is a bug, or a bugfix though. It kind of makes sense either way...

zambetpentru commented 3 years ago

Hi, thanks for your reply. I think it's a bug as the response from any PostGreSQL client is as it was with 2.3.0 and now the output isn't valid JSON any more.

I'm a bit new to GitHub so what's the best way to raise this?

isoos commented 3 years ago

I think the output is now a Map (which can be converted to JSON string via json.encode()). Having a Map there seems to be better, as it returns a parsed structure instead of a string that you need to parse...

zambetpentru commented 3 years ago

Hi @isoos, thanks so much for coming back to me with a solution - indeed if I update my app to wrap jsonEncode around the result from the query I get a proper JSON object again. :-)

In my case I'm using the database to generate JSON I can pass directly to my API.

I would say it's not a desirable default behaviour (but useful as an option) as my query above gives a single cell result string but now in 2.3.1 the package is deciding to try and parse it. I can also seem to override it with the following query:

 Select CONCAT('', array_to_json(array_agg(row_to_json(A)))) from (SELECT Publication_Key, Publication_Name, Client_Key, Created_Date, Publication_ID
FROM public.Publications
      ) A

If you decide to keep it as is it looks like you should rename the version 2.3.1 to 3.0.0 as it is a breaking change in line with the Dart Pub versioning: https://semver.org/spec/v2.0.0-rc.1.html

isoos commented 3 years ago

Hm, two additional things we can consider:

/cc @schultek the author of the given change in case there is more to it.