GeoGenius.ResultMapper (geo_genius v0.2.0)

Copy Markdown View Source

Maps a Postgrex.Result into structs by column name.

GeoGenius.AreaMatch and GeoGenius.ImportRun both project a query result with more than a dozen columns, several of them same-typed neighbours, into their own struct. Both need the same rule -- map by column name, never by position -- so it lives here once rather than as two copies that could drift apart.

Summary

Functions

Maps a query result into structs of module, using fields to translate column names to struct keys.

Functions

to_structs(result, fields, module)

@spec to_structs(Postgrex.Result.t(), %{optional(String.t()) => atom()}, module()) ::
  [struct()]

Maps a query result into structs of module, using fields to translate column names to struct keys.

Mapping is by column name rather than position. Both projections that use this declare more than a dozen columns with several same-typed neighbours, so a positional mapping would transpose two of them silently the first time a projection changed.

Raises if a column in the result has no entry in fields: an unmapped column is a projection bug to fix, not a value to drop silently.