ghdna / athena-express

Athena-Express can simplify executing SQL queries in Amazon Athena AND fetching cleaned-up JSON results in the same synchronous or asynchronous request - well suited for web applications.
https://www.npmjs.com/package/athena-express
MIT License
179 stars 70 forks source link

Fixed logic on addDataType function to set non-string values #52

Open rrcalvo opened 3 years ago

rrcalvo commented 3 years ago

I have a query that results nested objects, e.g. SELECT id, item.id, item.label, item.price, order.quantity, order.subtotal FROM orders

The current behaviour resulting data from the Items collection is: [{ id: "O-100", item: { id: "item-12345", label: "Printer", price: "123.99" }, order: { quantity: "1", subtotal: "123.99" qualifies_for_discount: "true" }, }]

I need the resulting nested objects non-string properties in the Items collection to be set as non-string, i.e. not in quotes. Expected result: [{ id: "O-100", item: { id: "item-12345", label: "Printer", price: 123.99 }, order: { quantity: 1, subtotal: 123.99 qualifies_for_discount: true }, }] To accomplish this, it seems the record data has to be converted into a flat object map so the loop in the addDataType function can iterate through all properties including those in the nested objects.

coveralls commented 3 years ago

Pull Request Test Coverage Report for Build 139


Totals Coverage Status
Change from base Build 136: 0.0%
Covered Lines: 3
Relevant Lines: 3

💛 - Coveralls
rrcalvo commented 3 years ago

Also, not sure if this is the best way to do object flatten and unflatten. I just followed the example on the top answer on: https://stackoverflow.com/questions/19098797/fastest-way-to-flatten-un-flatten-nested-json-objects Let me know if there's a better way to do this. Thanks.