mirror of
https://github.com/qfpl/applied-fp-course.git
synced 2024-11-26 14:43:53 +03:00
Add some more guidance:
- Indication that you need to complete the `FromRow` instance. - Construction of the `DBComment` type.
This commit is contained in:
parent
f69fc1bf39
commit
b43afca171
@ -32,7 +32,12 @@ import FirstApp.Types (Comment, CommentText,
|
||||
-- our database queries. This also allows things to change over time without
|
||||
-- having to rewrite all of the functions that need to interact with DB related
|
||||
-- things in different ways.
|
||||
--
|
||||
-- To help with that, we create a new data type that can hold our `Connection`
|
||||
-- for us, and allows it to be expanded later if we need to
|
||||
data FirstAppDB = FirstAppDB
|
||||
{ dbConn :: Connection
|
||||
}
|
||||
|
||||
-- Quick helper to pull the connection and close it down.
|
||||
closeDB
|
||||
|
@ -10,16 +10,19 @@ import Database.SQLite.Simple.FromRow (FromRow (fromRow), field)
|
||||
-- application, we create a stand alone type that will represent the data we
|
||||
-- store in the database. In this instance, it is the raw types that make up a
|
||||
-- comment.
|
||||
--
|
||||
|
||||
-- Complete in the DbComment type below so it is a record type that matches the
|
||||
-- Comment type, but without the newtype wrappers for each value.
|
||||
-- Comment type, but without the newtype wrappers for each value. To get started,
|
||||
-- just copy the new definition for the `Comment` type from FirstApp.Types.
|
||||
data DBComment = DBComment
|
||||
deriving Show
|
||||
-- NB: Haskell does not allow duplicate field names for records so the field
|
||||
-- names for this type will have to be slightly different
|
||||
|
||||
-- This Typeclass comes from the `sqlite-simple` package and describes how to
|
||||
-- decode a single row from the database into a single representation of our
|
||||
-- type. This technique of translating a result row to a type will differ
|
||||
-- between different packages/databases.
|
||||
instance FromRow DBComment where
|
||||
fromRow = error "FromRow DBComment instance not implemented"
|
||||
|
||||
-- Now move to ``src/FirstApp/Types.hs``
|
||||
|
Loading…
Reference in New Issue
Block a user