+
Skip to content

Conversation

guaraqe
Copy link

@guaraqe guaraqe commented May 12, 2023

This adds unsafe EXTRACT functions to Rel8.Expr.Time, using the low-level Opaleye functions. Should solve #236.

In principle a safe function can also be done with a GADT, but that would need more work.

@ocharles
Copy link
Contributor

ocharles commented Jul 7, 2023

I think I'd like to do this with some kind of GADT or something to track what is being extracted, rather than allowing any DBType.

@idontgetoutmuch
Copy link

I need this so I think I will use @guaraqe's PR until something better comes along.

@idontgetoutmuch
Copy link

And now I have

data Pair f = Pair
  { pairYear  :: Column f Double
  , pairMonth :: Column f Double
  , pairDayofMonth :: Column f Double
  }
  deriving stock (Generic)
  deriving anyclass (Rel8able)

deriving stock instance f ~ Result => Show (Pair f)

getYearMonth :: Query (Pair Expr)
getYearMonth = (\x -> let z = Rel8.fromDay x.dDate
                        in Pair { pairYear       = Rel8.unsafeExtractFromTime "YEAR" z
                                  , pairMonth      = Rel8.unsafeExtractFromTime "MONTH" z
                                  , pairDayofMonth = Rel8.unsafeExtractFromTime "DAY" z}) <$>
                 each daysInMonth

@ocharles if you are worried about type safety (which obviously we all are) what about some specific functions like toGregorian :: Day -> (Year, MonthOfYear, DayOfMonth)?

This adds unsafe EXTRACT function to Rel8.Expr.Time, using the low-level
Opaleye functions. Should solve circuithub#236.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载