Triing to use postgresql-client, does nothing

Hello,

I’m triing to create table using purescript-postgresql-client and it does nothing. I think it supposed to throw some kind of error since database is not created it don’t reach affLog "Connection" in run function

module Main where

import Prelude

import Data.Maybe (Maybe(Just))
import Data.Either (Either(Right, Left))
import Effect (Effect)
import Effect.Console (logShow)
import Effect.Aff (Aff, makeAff, launchAff_)
import Database.PostgreSQL (PoolConfiguration, newPool, withConnection, execute, defaultPoolConfiguration, PGError, Connection, Row0(Row0), Query(Query))

affLog :: forall a. Show a => a -> Aff Unit
affLog item = makeAff \done -> do
  _ <- logShow item
  pure mempty

config :: PoolConfiguration
config = 
  let default = defaultPoolConfiguration "purescript" 
  in default 
    { host = Just "localhost"
    , password = Just "postgres"
    , user = Just "postgres" 
    }

runExample :: Connection -> Aff Unit
runExample conn = do
  _ <- execute conn (Query """
    CREATE TABLE fruits (
      name text NOT NULL,
      delicious boolean NOT NULL,
      price NUMERIC(4,2) NOT NULL,
      added TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
      PRIMARY KEY (name)
    );
  """) Row0
  affLog "Success"

run :: Either PGError Connection -> Aff Unit
run eitherConnection = do
  affLog "Connection"
  case eitherConnection of
    Right conn -> runExample conn
    Left error -> affLog error

main :: Effect Unit
main = do
  pool <- newPool config
  launchAff_ do
    affLog "Run example"
    withConnection pool run

Subquestion could by that how to debug this kind of cases

Problem was with mi function affLog, I was not calling done, fixed version

affLog :: forall a. Show a => a -> Aff Unit
affLog item = makeAff \done -> do
  _ <- logShow item
  _ <- done (Right mempty)
  pure mempty
1 Like

As was probably mentioned in the other topic, you should be using this function instead of your custom affLog: https://pursuit.purescript.org/packages/purescript-console/4.4.0/docs/Effect.Class.Console#v:logShow

2 Likes