Get Record/Query all : Choose which fields to return on function stack call.

For the sake of efficiency and of being able to only get the required information, it would be great to be able to instruct a Query all to return only a selected amount of fields dynamically (as in defined at function stack call).

For example, if a table employee has 30 fields in it, but for a list of employees for a certain business role, I only require the first name, last name, salary and employment_status,

passing in "fields" a "text[]" like ["first_name","last_name","salary","status"]

would return

[{ "first_name": "Leila", "last_name", "Swatson", "salary": 45000, "status":"active"},{...},...]

It would simplify the stack as instead of writing the query 20 times for 20 different use cases (which is even worst when Addons are used) and having to maintain them when there's a change in a data structure, write it once with a selection of columns for each use case.

I suggest such improvement at database level since it would prevent unnecessary data fetch and really fine tune those query results so it only needs to do the necessary work.

The dev side of me is irritated by the number of Query All that has to be done and maintained for different scenarios. So I tend to be lazy and just fetch all the data on a centralized Query All and either create a new object from the fetched data, or "unset" some fields in the result. However, the DB manager side of me is infuriated at the dev side of me because of the large amount of data transferred and inefficiency of the dev's method and would prefer the query to be as efficient as possible, at all time.

I know there could be some potential challenges to writing such query, such as how do we represent nested objects and arrays, but I feel that if we could find solutions for these challenges, this could be interesting ๐Ÿ™‚ .

2
3 replies