haskell-beam / haskell-beam/beam
Time operations in postgresql backend don't seem to support arithmetic
- Dominant language
- Haskell
- Stars
- 635
- Forks
- 193
- PR merge metrics
- No merged PRs in 30d
Description
Hi there,
I've recently started experimenting with beam, and it's really a pleasure to use so far!
However, I've run into an issue regarding performing arithmetic on times: I can't seem to perform subtraction in a sane way. In pure Haskell, using the canonical `time` library, we have `NominalDiffTime`, which supports `addUTCTime` and `diffUTCTime` in order to work around addition and subtraction being against seconds rather than another `UTCTime`. I think there would need to be something similar in this library to support these sorts of cases, as time is often used in databases.
Here's a small chunk of code that demonstrates my current dilemma, in case I'm missing something obvious:
``` haskell
data IdempotencyKeyT f = IdempotencyKey
{ idempotencyKeyId :: C f (Auto Int64)
, idempotencyKeyCreatedAt :: C f (Auto UTCTime)
} deriving (Generic)
... boilerplate
localTimestamp :: QExpr PgExpressionSyntax s UTCTime
localTimestamp = customExpr_ "localtimestamp"
runDelete $ delete (dbIdempotencyKeys dbSettings) $ \key ->
idempotencyKeyCreatedAt key <. auto_
(localTimestamp `subE` (val_ aDiffTimeGoesHere))
```
Thanks in advance for any suggestions you might have!
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.