module Polysemy.Hasql.Data.ConnectionState where

import Control.Concurrent (ThreadId)
import Hasql.Connection (Connection)

import Polysemy.Hasql.Data.InitDb (ClientTag)

data ConnectionState =
  ConnectionState {
    ConnectionState -> Int
count :: Int,
    ConnectionState -> Maybe Connection
connection :: Maybe Connection,
    ConnectionState -> Map ThreadId Int
activeCommands :: Map ThreadId Int
  }
  deriving stock (forall x. Rep ConnectionState x -> ConnectionState
forall x. ConnectionState -> Rep ConnectionState x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ConnectionState x -> ConnectionState
$cfrom :: forall x. ConnectionState -> Rep ConnectionState x
Generic)

instance Default ConnectionState where
  def :: ConnectionState
def =
    Int -> Maybe Connection -> Map ThreadId Int -> ConnectionState
ConnectionState Int
0 forall a. Maybe a
Nothing forall a. Monoid a => a
mempty

data ConnectionsState =
  ConnectionsState {
    ConnectionsState -> Integer
counter :: Integer,
    ConnectionsState -> Map ClientTag Int
clientInits :: Map ClientTag Int
  }
  deriving stock (ConnectionsState -> ConnectionsState -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ConnectionsState -> ConnectionsState -> Bool
$c/= :: ConnectionsState -> ConnectionsState -> Bool
== :: ConnectionsState -> ConnectionsState -> Bool
$c== :: ConnectionsState -> ConnectionsState -> Bool
Eq, Int -> ConnectionsState -> ShowS
[ConnectionsState] -> ShowS
ConnectionsState -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ConnectionsState] -> ShowS
$cshowList :: [ConnectionsState] -> ShowS
show :: ConnectionsState -> String
$cshow :: ConnectionsState -> String
showsPrec :: Int -> ConnectionsState -> ShowS
$cshowsPrec :: Int -> ConnectionsState -> ShowS
Show, forall x. Rep ConnectionsState x -> ConnectionsState
forall x. ConnectionsState -> Rep ConnectionsState x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ConnectionsState x -> ConnectionsState
$cfrom :: forall x. ConnectionsState -> Rep ConnectionsState x
Generic)