The most used database abstraction library in Haskell HDBC . This means that queries are simply represented as String with placeholders. Fewer people use HaskellDB , which provides a secure type of query building. Nothing prohibits the use of custom data types to represent common queries and custom functions to create them.
The values ββin Haskell are immutable, which means that it is not practical to have a mutable object corresponding to a record in the database. Instead, I believe that the types and functions of user data that march and push / transfer the values ββof these types to / from the database are most often defined.
Whenever database updates are needed, they are likely to run in some kind of monopoly monad in IO . This will keep the connection open, for example, or do something between requests.
Finally, the functions are first-class, so you can build all the functions on the fly. Thus, the function itself can encapsulate any necessary information.
So, I think the normal Haskell approach consists of
- algebraic data types for representing actual data (as constant values)
- the rest of the application to convert these values
- which generate requests (encapsulate schema details, marshal data to / from Haskell data types)
- (optional) a monad with a state to run queries (hide database access information)
- functions that run queries (hide database access information)
sastanin
source share