emg184
emg184

Reputation: 1010

How to create a Heterogenous map of SqlField's without reimplementing every possible SqlField in Haskell

I want to use the postgresql-simple library to construct a Map or HashMap of SqlValues. I know one approach to do this would be to redefine all of the SqlValue's into a single universal type ala

data SqlValue = SqlInt Int
              | SqlString String
              | SqlJson Value
              etc

But I am wondering if there is a more effective way of doing this where I can create a map that allows it's value's to be any type that implement's the FromField class.

Is it possible to at the least reduce the amount of overhead associated with it by using TypeFamilies or something similar where I can take make each instance of the type also require an instance of FromField

The end goal is to have postgresql-simple produce something along the lines of the following:

[Map SqlColumnName SqlValue]

Upvotes: 0

Views: 49

Answers (0)

Related Questions