module Database.Beam.Query.Extract
(
ExtractField(..),
extract_,
hour_, minutes_, seconds_,
year_, month_, day_,
HasSqlTime, HasSqlDate
) where
import Database.Beam.Query.Internal ( QGenExpr(..) )
import Database.Beam.Backend.SQL ( BeamSqlBackend, BeamSqlBackendSyntax )
import Database.Beam.Backend.SQL.SQL92 ( Sql92ExtractFieldSyntax
, IsSql92ExpressionSyntax(..)
, IsSql92ExtractFieldSyntax(..) )
import Data.Time (LocalTime, UTCTime, TimeOfDay, Day)
newtype ExtractField be tgt a
= ExtractField (Sql92ExtractFieldSyntax (BeamSqlBackendSyntax be))
extract_ :: BeamSqlBackend be
=> ExtractField be tgt a -> QGenExpr ctxt be s tgt -> QGenExpr cxt be s a
extract_ (ExtractField field) (QExpr expr) =
QExpr (extractE field <$> expr)
class HasSqlTime tgt
instance HasSqlTime LocalTime
instance HasSqlTime UTCTime
instance HasSqlTime TimeOfDay
hour_, minutes_, seconds_
:: ( BeamSqlBackend be, HasSqlTime tgt )
=> ExtractField be tgt Double
hour_ = ExtractField hourField
minutes_ = ExtractField minutesField
seconds_ = ExtractField secondsField
class HasSqlDate tgt
instance HasSqlDate LocalTime
instance HasSqlDate UTCTime
instance HasSqlDate Day
year_, month_, day_
:: ( BeamSqlBackend be, HasSqlDate tgt )
=> ExtractField be tgt Double
year_ = ExtractField yearField
month_ = ExtractField monthField
day_ = ExtractField dayField