Remove certain fields from schema in a query

I am working on a query library, which provides ease of making complex queries. I added a feature to blacklist some fields like passwords or other similar fields, which can not be accessed. It’s working in case of select, group_by, join. It returns an error if the user is trying to query a field that is blacklisted.

The problem is with where and preload. It returns an error if we try to query a blacklisted field with where but returns the record with all the blacklisted fields if we query some other non-blacklisted field. similar is the case with preload. It returns the complete record with all the blacklisted fields included.

It’s an open-source library so removing blacklisted fields from the Jason encoder is not an option.

Can you please suggest any solutions.


If i understand your question correctly you will need something like elixir did in the release of version 1.8. (Custom struct inspections)
You will need to write for each struct a derive with a custom protocol see: