valderman / selda

A type-safe, high-level SQL library for Haskell
https://selda.link
MIT License
478 stars 58 forks source link

fromSql for invalid SQL column value #155

Open jchia opened 3 years ago

jchia commented 3 years ago

Suppose I want to make an SqlType instance for my own data type that can be represented as a value in an SQL column. E.g. I want to represent integers from 0 to 1000:

newtype SmallInt = SmallInt { unSmallInt :: Int }

I could define mkLit (SmallInt x) = LInt x. However, converting in the other direction, what should be done in fromSql if the input is an out-of-range SqlInt value? Just error? How does the user detect an error in the input when running a query?