Skip to content

Instantly share code, notes, and snippets.

@rnons
Created December 19, 2019 12:49
Show Gist options
  • Save rnons/6802f9ffd64b5da9909e28c654f81684 to your computer and use it in GitHub Desktop.
Save rnons/6802f9ffd64b5da9909e28c654f81684 to your computer and use it in GitHub Desktop.
A persistent playground
-- 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 ()
{ 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