Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show minimal persistent example in Github project page and Hackage package page #1479

Open
malteneuss opened this issue Mar 8, 2023 · 1 comment

Comments

@malteneuss
Copy link
Contributor

malteneuss commented Mar 8, 2023

Hi,
i would like to add the minimal usage example of the Yesod-Book in https://www.yesodweb.com/book/persistent#persistent_synopsis to the README so that it appears on the main Github project landing page and Hackage package landing page, because i really like this style from the Rust community; You can quickly copy-paste a working example and get a feel for the operators. See Serde, Rocket, Askama etc. Would that be desired?

Maybe make the example even shorter? E.g.

{-# LANGUAGE EmptyDataDecls             #-}
{-# LANGUAGE FlexibleContexts           #-}
{-# LANGUAGE GADTs                      #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses      #-}
{-# LANGUAGE OverloadedStrings          #-}
{-# LANGUAGE QuasiQuotes                #-}
{-# LANGUAGE TemplateHaskell            #-}
{-# LANGUAGE TypeFamilies               #-}
import           Control.Monad.IO.Class  (liftIO)
import           Database.Persist
import           Database.Persist.Sqlite
import           Database.Persist.TH
import           Data.Text

share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase|
Person
    name Text
    age Int Maybe
    deriving Show
|]

main :: IO ()
main = runSqlite ":memory:" $ do
    -- setup db schema
    runMigration migrateAll
    
    -- write to db
    insert $ Person "Jane Doe" Nothing
    johnId <- insert $ Person "John Doe" $ Just 35

    -- read from db
    john1 <- selectList [PersonId ==. johnId] [LimitTo 1]
    john2 <- get johnId

    liftIO $ print (john1 :: [Entity Person])
    liftIO $ print (john2 :: Maybe Person)
    
    -- delete from db
    delete johnId
    deleteWhere [PersonId ==. johnId]
@malteneuss
Copy link
Contributor Author

malteneuss commented Mar 17, 2023

I added a PR. Ideally, the README with an example would also appear in Hackage: https://hackage.haskell.org/package/persistent. Please let me know how if that's desired as well and i could do that.

I would like to add similar minimal examples into the README of persistent-postgresql (and possible the others)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant