Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add EXTRACT function to Rel8.Expr.Time #237

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

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.

This adds unsafe EXTRACT function to Rel8.Expr.Time, using the low-level
Opaleye functions. Should solve circuithub#236.
@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)?

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.

None yet

3 participants