Hello.
I’m using a PostgreSQL-backed Ecto schema with a field :fields, :map, default: %{} to store some custom fields. I’d like to limit the size of this map, to have some control over the storage size of this table.
I am not sure where to add this check in an elegant way:
- The map is deserialized by a GraphQL/Absinthe custom scalar deserializer. I could check for size limit here, but I would have to return just
:errorwhen it’s exceeded, the same as in case of parse error. To the API user this would not be kind - start showing deserialize error after input size crosses a threshold. This approach would also mean i have to define one limit for all JSONBs, regardless of their use. - In resolver, the input is already parsed into a map. That map ends up in changeset - to check it’s size I would have to serialize it to JSON just to check the length of the string, which seems like a waste of CPU cycles.
3.. In the DB there is no way I am aware of to limit the size of JSONB column.
Any tips on how to overcome this?






















