As you probably already know, one of Haskell's strengths is strong typing. The persistent-sqlite package does this to the extreme (which, in my opinion, is good), requiring that the records in the table have their own data type.
For example, if you have a table that stores fruits that look like
_______________________
|Fruit ID | Fruit Name|
-----------------------
| 0 | "apple" |
| 1 | "orange" |
-----------------------
persistent-sqlite, Fruit
data Fruit = Fruit { fruitName::String }
, . , , Haskell magic , .
share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase|
Fruit
name String
deriving Show
|]
, . , , ,
The type variable ‘val0’ is ambiguous
: " , sql".
print (fruits :: [Entity Fruit])
, , GHC. , .
{-
{-
{-
{-
{-
{-
{-
import Control.Monad.IO.Class (liftIO)
import Database.Persist.Sqlite
import Database.Persist.TH
share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase|
Fruit
name String
deriving Show
|]
main :: IO ()
main = runSqlite "fruitDb.sqlite" $ do
fruits <- selectList [] [LimitTo 10]
liftIO $ print (fruits :: [Entity Fruit])
, sqlite db, .
> sqlite3 fruitDb.sqlite
sqlite> create table fruit (id, name);
sqlite> insert into fruit values (0, "apple");
sqlite> insert into fruit values (1, "orange");