mirror of
https://github.com/qfpl/applied-fp-course.git
synced 2024-11-23 03:44:45 +03:00
Wording updates, description adjustments
This commit is contained in:
parent
71e9982e08
commit
f458bb074f
@ -14,6 +14,9 @@ with the [hspec-wai] package to make our lives a bit easier.
|
||||
|
||||
Start in ``tests/Test.hs``.
|
||||
|
||||
[HSpec]: (http://hspec.github.io/)
|
||||
[hspec-wai]: (https://hackage.haskell.org/package/hspec-wai)
|
||||
|
||||
#### Aside: Tool Introduction - ghcid
|
||||
|
||||
Additionally we'd like to introduce a command line tool that you may find useful
|
||||
@ -33,6 +36,4 @@ messages or ``All Good`` if it cannot find any errors.
|
||||
process with constant feedback about your changes. It is very useful in tandem
|
||||
with type holes. Give it a try!
|
||||
|
||||
[HSpec]: (http://hspec.github.io/)
|
||||
[hspec-wai]: (https://hackage.haskell.org/package/hspec-wai)
|
||||
[ghcid]: (https://github.com/ndmitchell/ghcid)
|
||||
|
@ -1,15 +1,21 @@
|
||||
# Level 05
|
||||
|
||||
We need a place to store our Comments/Topics, so we're going to use the SQLite
|
||||
database. We've chosen SQLite because it takes the least amount of setup for the
|
||||
purposes of the course. There is an example module included for using PostgreSQL,
|
||||
however the course will focus on the SQLite implementation.
|
||||
We need a place to store our Comments/Topics, so we're going to add a database
|
||||
to our application, specifically the SQLite database. We've chosen SQLite
|
||||
because it was the simplest to have up and running for the purposes of the
|
||||
course.
|
||||
|
||||
There is an example module included for using PostgreSQL, however the course
|
||||
will focus on the SQLite implementation.
|
||||
|
||||
For reference, the packages we will use to talk to our database are:
|
||||
|
||||
- [sqlite-simple](https://hackage.haskell.org/package/sqlite-simple)
|
||||
- [sqlite-simple-errors](https://hackage.haskell.org/package/sqlite-simple-errors)
|
||||
|
||||
You will also need the [SQLite](https://www.sqlite.org/) database application
|
||||
installed and available on your system.
|
||||
|
||||
Start in ``src/FirstApp/DB/Types.hs``, before moving to ``src/FirstApp/DB.hs``.
|
||||
|
||||
NB: The PostgreSQL example module is in ``src/FirstApp/DB/PostgreSQL.hs``.
|
||||
|
@ -29,8 +29,8 @@ import FirstApp.Types
|
||||
-- ------------------------------------------------------------------------|
|
||||
|
||||
-- We need to have a way to pass around the name of the Table we're going to us
|
||||
-- for the comments in this application. We _could_ pass around a `Text` value.
|
||||
-- What should we do instead?
|
||||
-- for the comments in this application. We _could_ pass around a `Text` value,
|
||||
-- but we can be better than that.
|
||||
newtype Table = Table Text
|
||||
deriving Show
|
||||
|
||||
@ -47,13 +47,13 @@ closeDb
|
||||
closeDb =
|
||||
error "closeDb not implemented"
|
||||
|
||||
-- Due to the way our application is designed, we have a slight SQL injection
|
||||
-- risk because we pull the `Table` from the `Conf`. Write a function that
|
||||
-- attempts to mitigate that risk a bit, by handling replacement of a place-
|
||||
-- holder value in a given Query. We should be able to write the query and pass
|
||||
-- it through this function and everything is will be taken care of for us.
|
||||
-- Because our `Table` is as a configurable value, this application has a SQL
|
||||
-- injection vulnerability. Write a function that attempts to mitigate that
|
||||
-- risk, by handling replacement of a place-holder value in a given `Query`. We
|
||||
-- should be able to write the query and pass it through this function and
|
||||
-- everything is will be taken care of for us.
|
||||
|
||||
-- This is not the way to do things in a large scale app, obviously.
|
||||
-- This is _not_ the way to do things in a large scale app, obviously.
|
||||
withTable
|
||||
:: Table
|
||||
-> Query
|
||||
|
@ -13,8 +13,8 @@ import Database.SQLite.Simple.FromRow (FromRow (..), field)
|
||||
data DbComment = DbComment
|
||||
deriving Show
|
||||
|
||||
-- This typeclass instance comes from our DB package and tells the DB package
|
||||
-- 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
|
||||
-- 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
|
||||
|
@ -122,9 +122,9 @@ handleRequest
|
||||
handleRequest _ _db (AddRq _ _) =
|
||||
fmap (const ( resp200 PlainText "Success" )) <$> undefined
|
||||
handleRequest _ _db (ViewRq _) =
|
||||
fmap undefined <$> undefined
|
||||
fmap undefined <$> undefined
|
||||
handleRequest _ _db ListRq =
|
||||
fmap undefined <$> undefined
|
||||
fmap undefined <$> undefined
|
||||
|
||||
mkRequest
|
||||
:: Request
|
||||
|
Loading…
Reference in New Issue
Block a user