generated from tpl/purs
refactor: bun run fmt
This commit is contained in:
@@ -74,7 +74,8 @@ instance
|
||||
( MonadAff m
|
||||
, MonadSession (SessionT m)
|
||||
, MonadCursor (CursorT t (SessionT m)) t
|
||||
) => MonadPostgres
|
||||
) =>
|
||||
MonadPostgres
|
||||
(PostgresT m)
|
||||
(SessionT m)
|
||||
(CursorT ct (SessionT m))
|
||||
@@ -117,6 +118,7 @@ runPostgres cfg m =
|
||||
let
|
||||
acq :: RE Unit m Pool
|
||||
acq = liftEffect $ Pool.make @r @missing @trash cfg
|
||||
|
||||
rel :: _ -> Pool -> RE Unit m Unit
|
||||
rel _ p = RE.liftExcept $ hoist liftAff $ Pool.end p
|
||||
in
|
||||
|
||||
@@ -9,7 +9,7 @@ import Data.Time.Duration (class Duration, Days(..), Hours(..), Milliseconds(..)
|
||||
import Effect (Effect)
|
||||
|
||||
zero :: IntervalRecord
|
||||
zero = {years: 0, months: 0, days: 0, hours: 0, minutes: 0, seconds: 0, milliseconds: 0.0}
|
||||
zero = { years: 0, months: 0, days: 0, hours: 0, minutes: 0, seconds: 0, milliseconds: 0.0 }
|
||||
|
||||
type IntervalRecord =
|
||||
{ years :: Int
|
||||
@@ -85,4 +85,4 @@ fromDuration a =
|
||||
seconds = Int.trunc $ minutesRem / secondFactor
|
||||
milliseconds = minutesRem - (Int.toNumber seconds * secondFactor)
|
||||
in
|
||||
make {years: 0, months: 0, days, hours, minutes, seconds, milliseconds}
|
||||
make { years: 0, months: 0, days, hours, minutes, seconds, milliseconds }
|
||||
|
||||
@@ -8,15 +8,16 @@ export const isInstanceOfBuffer = a => a instanceof Buffer
|
||||
|
||||
/** @type {(a: unknown) => boolean} */
|
||||
export const isInstanceOfInterval = a => {
|
||||
return typeof a === 'object'
|
||||
&& a !== null
|
||||
&& ('years' in a
|
||||
|| 'months' in a
|
||||
|| 'days' in a
|
||||
|| 'hours' in a
|
||||
|| 'minutes' in a
|
||||
|| 'seconds' in a
|
||||
|| 'milliseconds' in a
|
||||
return (
|
||||
typeof a === 'object' &&
|
||||
a !== null &&
|
||||
('years' in a ||
|
||||
'months' in a ||
|
||||
'days' in a ||
|
||||
'hours' in a ||
|
||||
'minutes' in a ||
|
||||
'seconds' in a ||
|
||||
'milliseconds' in a)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import Effect.Postgres.Error as E
|
||||
import Effect.Postgres.Error.Except as E.Except
|
||||
import Effect.Postgres.Pool (Pool)
|
||||
import Effect.Postgres.Pool
|
||||
(Config
|
||||
( Config
|
||||
, Pool
|
||||
, PoolConfigRaw
|
||||
, acquireE
|
||||
|
||||
@@ -45,7 +45,7 @@ spec =
|
||||
b `shouldEqual` 2
|
||||
it "multiple sessions concurrently" \cfg -> do
|
||||
nums <- X.run $ runPostgres cfg $ parTraverse (\n -> query $ "select $1 :: int" /\ n) (Array.range 1 3)
|
||||
Array.sort nums `shouldEqual` [1, 2, 3]
|
||||
Array.sort nums `shouldEqual` [ 1, 2, 3 ]
|
||||
it "transaction commits" \cfg -> do
|
||||
a <- X.run $ runPostgres cfg do
|
||||
exec_ "create temporary table test_txn_commits (id int);"
|
||||
@@ -60,7 +60,7 @@ spec =
|
||||
exec_ "insert into test_txn_rolls_back values (2);"
|
||||
throwError $ pure $ E.Other $ error "foo"
|
||||
query "select * from test_txn_rolls_back"
|
||||
a `shouldEqual` [1]
|
||||
a `shouldEqual` [ 1 ]
|
||||
it "cursor" \cfg ->
|
||||
X.run $ runPostgres cfg do
|
||||
exec_ $ "create temporary table test_cursor_data (id int primary key generated always as identity)"
|
||||
|
||||
@@ -15,23 +15,23 @@ spec =
|
||||
describe "Data.Postgres.Interval" do
|
||||
it "parse & toRecord" do
|
||||
p <- liftEffect $ Interval.parse "3 days 04:05:06"
|
||||
Interval.toRecord p `shouldEqual` Interval.zero {days = 3, hours = 4, minutes = 5, seconds = 6}
|
||||
Interval.toRecord p `shouldEqual` Interval.zero { days = 3, hours = 4, minutes = 5, seconds = 6 }
|
||||
|
||||
it "make & toRecord" do
|
||||
let p = Interval.make $ Interval.zero {days = 3, hours = 4, minutes = 5, seconds = 6}
|
||||
Interval.toRecord p `shouldEqual` Interval.zero {days = 3, hours = 4, minutes = 5, seconds = 6}
|
||||
let p = Interval.make $ Interval.zero { days = 3, hours = 4, minutes = 5, seconds = 6 }
|
||||
Interval.toRecord p `shouldEqual` Interval.zero { days = 3, hours = 4, minutes = 5, seconds = 6 }
|
||||
|
||||
describe "fromDuration" do
|
||||
for_
|
||||
[ Milliseconds 100.0 /\ Interval.zero {milliseconds = 100.0}
|
||||
, Milliseconds 1000.0 /\ Interval.zero {seconds = 1}
|
||||
, Milliseconds 1100.0 /\ Interval.zero {seconds = 1, milliseconds = 100.0}
|
||||
, Milliseconds 60000.0 /\ Interval.zero {minutes = 1}
|
||||
, Milliseconds 61100.0 /\ Interval.zero {minutes = 1, seconds = 1, milliseconds = 100.0}
|
||||
, Milliseconds 3600000.0 /\ Interval.zero {hours = 1}
|
||||
, Milliseconds 3661100.0 /\ Interval.zero {hours = 1, minutes = 1, seconds = 1, milliseconds = 100.0}
|
||||
, Milliseconds 86400000.0 /\ Interval.zero {days = 1}
|
||||
, Milliseconds 90061100.0 /\ Interval.zero {days = 1, hours = 1, minutes = 1, seconds = 1, milliseconds = 100.0}
|
||||
[ Milliseconds 100.0 /\ Interval.zero { milliseconds = 100.0 }
|
||||
, Milliseconds 1000.0 /\ Interval.zero { seconds = 1 }
|
||||
, Milliseconds 1100.0 /\ Interval.zero { seconds = 1, milliseconds = 100.0 }
|
||||
, Milliseconds 60000.0 /\ Interval.zero { minutes = 1 }
|
||||
, Milliseconds 61100.0 /\ Interval.zero { minutes = 1, seconds = 1, milliseconds = 100.0 }
|
||||
, Milliseconds 3600000.0 /\ Interval.zero { hours = 1 }
|
||||
, Milliseconds 3661100.0 /\ Interval.zero { hours = 1, minutes = 1, seconds = 1, milliseconds = 100.0 }
|
||||
, Milliseconds 86400000.0 /\ Interval.zero { days = 1 }
|
||||
, Milliseconds 90061100.0 /\ Interval.zero { days = 1, hours = 1, minutes = 1, seconds = 1, milliseconds = 100.0 }
|
||||
]
|
||||
\(i /\ o) -> it ("converts " <> show i) do
|
||||
Interval.toRecord (Interval.fromDuration i) `shouldEqual` o
|
||||
|
||||
@@ -59,7 +59,7 @@ instance Arbitrary GenIntervalSubMonth where
|
||||
minutes <- chooseInt 0 59
|
||||
seconds <- chooseInt 0 59
|
||||
milliseconds <- chooseFloat 0.0 999.9
|
||||
pure $ wrap $ Interval.make $ Interval.zero {days = days, hours = hours, minutes = minutes, seconds = seconds, milliseconds = milliseconds}
|
||||
pure $ wrap $ Interval.make $ Interval.zero { days = days, hours = hours, minutes = minutes, seconds = seconds, milliseconds = milliseconds }
|
||||
|
||||
newtype GenInterval = GenInterval Interval
|
||||
|
||||
@@ -73,7 +73,7 @@ instance Arbitrary GenInterval where
|
||||
minutes <- chooseInt 0 59
|
||||
seconds <- chooseInt 0 59
|
||||
milliseconds <- chooseFloat 0.0 999.9
|
||||
pure $ wrap $ Interval.make {years, months, days, hours, minutes, seconds, milliseconds}
|
||||
pure $ wrap $ Interval.make { years, months, days, hours, minutes, seconds, milliseconds }
|
||||
|
||||
newtype GenSmallInt = GenSmallInt Int
|
||||
|
||||
@@ -225,13 +225,14 @@ spec =
|
||||
let
|
||||
durationFromGenInterval :: forall d. Semigroup d => Duration d => Newtype d Number => GenIntervalSubMonth -> d
|
||||
durationFromGenInterval = fromMaybe (wrap 0.0) <<< Interval.toDuration <<< unwrap
|
||||
|
||||
durationEq :: forall d. Duration d => Newtype d Number => d -> d -> Boolean
|
||||
durationEq a b = Number.abs (unwrap a - unwrap b) <= 0.001
|
||||
check @Milliseconds @GenIntervalSubMonth { purs: "Milliseconds", sql: "interval", fromArb: durationFromGenInterval, isEq: durationEq}
|
||||
check @Seconds @GenIntervalSubMonth { purs: "Seconds", sql: "interval", fromArb: durationFromGenInterval, isEq: durationEq}
|
||||
check @Minutes @GenIntervalSubMonth { purs: "Minutes", sql: "interval", fromArb: durationFromGenInterval, isEq: durationEq}
|
||||
check @Hours @GenIntervalSubMonth { purs: "Hours", sql: "interval", fromArb: durationFromGenInterval, isEq: durationEq}
|
||||
check @Days @GenIntervalSubMonth { purs: "Days", sql: "interval", fromArb: durationFromGenInterval, isEq: durationEq}
|
||||
check @Milliseconds @GenIntervalSubMonth { purs: "Milliseconds", sql: "interval", fromArb: durationFromGenInterval, isEq: durationEq }
|
||||
check @Seconds @GenIntervalSubMonth { purs: "Seconds", sql: "interval", fromArb: durationFromGenInterval, isEq: durationEq }
|
||||
check @Minutes @GenIntervalSubMonth { purs: "Minutes", sql: "interval", fromArb: durationFromGenInterval, isEq: durationEq }
|
||||
check @Hours @GenIntervalSubMonth { purs: "Hours", sql: "interval", fromArb: durationFromGenInterval, isEq: durationEq }
|
||||
check @Days @GenIntervalSubMonth { purs: "Days", sql: "interval", fromArb: durationFromGenInterval, isEq: durationEq }
|
||||
|
||||
check @Int @GenSmallInt { purs: "Int", sql: "int2", fromArb: unwrap, isEq: eq }
|
||||
check @Int { purs: "Int", sql: "int4", fromArb: identity, isEq: eq }
|
||||
|
||||
@@ -121,7 +121,8 @@ spec =
|
||||
either <-
|
||||
flip RE.toEither unit
|
||||
$ parSequence
|
||||
$ [ liftAff $ throwError $ Exn.error "a"
|
||||
$
|
||||
[ liftAff $ throwError $ Exn.error "a"
|
||||
, pure "a"
|
||||
]
|
||||
isLeft either `shouldEqual` true
|
||||
@@ -129,7 +130,8 @@ spec =
|
||||
either <-
|
||||
flip RE.toEither unit
|
||||
$ parOneOf
|
||||
$ [ liftAff $ throwError $ Exn.error "a"
|
||||
$
|
||||
[ liftAff $ throwError $ Exn.error "a"
|
||||
, liftAff $ throwError $ Exn.error "b"
|
||||
]
|
||||
isLeft either `shouldEqual` true
|
||||
|
||||
@@ -49,13 +49,13 @@ spec = describe "Pool" do
|
||||
c <- X.run $ Pool.connect p
|
||||
finally (liftEffect $ X.run $ Pool.release p c) $ joinFiber expect
|
||||
it "acquire" \p -> do
|
||||
c <- X.run$ Pool.connect p
|
||||
liftEffect $ X.run$ Pool.release p c
|
||||
c <- X.run $ Pool.connect p
|
||||
liftEffect $ X.run $ Pool.release p c
|
||||
expect <- forkAff do
|
||||
c'' <- onceAff Pool.acquireE p
|
||||
refEq c c'' `shouldEqual` true
|
||||
c' <- X.run $ Pool.connect p
|
||||
finally (liftEffect $ X.run$ Pool.release p c') $ joinFiber expect
|
||||
finally (liftEffect $ X.run $ Pool.release p c') $ joinFiber expect
|
||||
it "release" \p -> do
|
||||
c <- X.run $ Pool.connect p
|
||||
expect <- forkAff do
|
||||
|
||||
Reference in New Issue
Block a user