[Haskell-cafe] Using Haskell types in a database
nikita at karetnikov.org
Tue Feb 10 18:02:58 UTC 2015
> That part I don't understand. Why does your proposal require varchars
That's what Persistent generates (using derivePersistField) for the
second table. For example, the Haskell value
where MyText is
newtype MyText = MyText Text deriving (Show, Read)
will be stored in PostgreSQL as a varchar
I assume that Persistent (or its PostgreSQL backend) has a predefined
mapping from a commonly used Haskell types to the database types.
And everything else is represented as a varchar.
So there are two choices, corresponding to the two tables shown in the
1. Design tables with the (basic) database types in mind (integer,
boolean, timestamp, varchar, etc.) then wrap and unwrap values each
time you interact with the database.
2. Use Haskell types like MyText or something more complex directly
and end up with varchar everywhere.
I wonder how bad is the second option in practice because
wrapping/unwrapping is error-prone. Of course, the varchar thing makes
the alarm bells ring in my head, but when does it significantly affect
performance? For example, maybe it's okay for a small shop, or is it a
no go for everyone?
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 818 bytes
Desc: not available
More information about the Haskell-Cafe