Created
December 19, 2019 12:49
-
-
Save rnons/6802f9ffd64b5da9909e28c654f81684 to your computer and use it in GitHub Desktop.
A persistent playground
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- nix-shell | |
-- ghcid -c 'ghci Main.hs' | |
{-# LANGUAGE GADTs #-} | |
{-# LANGUAGE GeneralizedNewtypeDeriving #-} | |
{-# LANGUAGE MultiParamTypeClasses #-} | |
{-# LANGUAGE OverloadedStrings #-} | |
{-# LANGUAGE QuasiQuotes #-} | |
{-# LANGUAGE ScopedTypeVariables #-} | |
{-# LANGUAGE TemplateHaskell #-} | |
{-# LANGUAGE TypeFamilies #-} | |
import Control.Monad.Logger (runLoggingT) | |
import Data.ByteString (ByteString) | |
import Database.Persist | |
import Database.Persist.Postgresql | |
import Database.Persist.TH | |
share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase| | |
Post | |
name ByteString | |
deriving Show | |
|] | |
main :: IO () | |
main = do | |
pool <- | |
flip runLoggingT (\_ _ _ _ -> pure ()) $ | |
createPostgresqlPool "postgresql://postgres:postgres@localhost:5432/bytea" 5 | |
flip runSqlPool pool $ do | |
runMigration migrateAll | |
insert $ Post "\160" | |
pure () |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ nixpkgs ? import <nixpkgs> {}, compiler ? "ghc865" }: | |
let | |
inherit (nixpkgs) pkgs; | |
ghc = pkgs.haskell.packages.${compiler}.ghcWithPackages (ps: with ps; [ | |
persistent persistent-template persistent-postgresql | |
]); | |
in | |
pkgs.stdenv.mkDerivation { | |
name = "persistent-playground"; | |
buildInputs = [ ghc ]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment