packages feed

opaleye 0.6.0.0 → 0.6.1.0

raw patch · 22 files changed

+175/−66 lines, 22 filesdep ~product-profunctorsPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependency ranges changed: product-profunctors

API changes (from Hackage documentation)

- Opaleye.Constant: instance Data.Profunctor.Product.Default.Class.Default Opaleye.Constant.Constant (Database.PostgreSQL.Simple.Range.PGRange Data.Time.Clock.UTC.UTCTime) (Opaleye.Internal.Column.Column (Opaleye.PGTypes.PGRange Opaleye.PGTypes.PGTimestamptz))
- Opaleye.Constant: instance Data.Profunctor.Product.Default.Class.Default Opaleye.Constant.Constant (Database.PostgreSQL.Simple.Range.PGRange Data.Time.LocalTime.LocalTime.LocalTime) (Opaleye.Internal.Column.Column (Opaleye.PGTypes.PGRange Opaleye.PGTypes.PGTimestamp))
- Opaleye.Constant: instance Data.Profunctor.Product.Default.Class.Default Opaleye.Constant.Constant Data.Time.Clock.UTC.UTCTime (Opaleye.Internal.Column.Column Opaleye.PGTypes.PGTimestamptz)
- Opaleye.Constant: instance Data.Profunctor.Product.Default.Class.Default Opaleye.Constant.Constant Data.Time.LocalTime.LocalTime.LocalTime (Opaleye.Internal.Column.Column Opaleye.PGTypes.PGTimestamp)
- Opaleye.Constant: instance Data.Profunctor.Product.Default.Class.Default Opaleye.Constant.Constant Data.Time.LocalTime.TimeOfDay.TimeOfDay (Opaleye.Internal.Column.Column Opaleye.PGTypes.PGTime)
- Opaleye.Constant: instance Data.Profunctor.Product.SumProfunctor Opaleye.Constant.Constant
- Opaleye.Internal.Aggregate: instance Data.Profunctor.Product.SumProfunctor Opaleye.Internal.Aggregate.Aggregator
- Opaleye.Internal.Distinct: instance Data.Profunctor.Product.SumProfunctor Opaleye.Internal.Distinct.Distinctspec
- Opaleye.Internal.PackMap: instance Data.Profunctor.Product.SumProfunctor (Opaleye.Internal.PackMap.PackMap a b)
- Opaleye.Internal.RunQuery: instance Data.Profunctor.Product.SumProfunctor Opaleye.Internal.RunQuery.QueryRunner
- Opaleye.Internal.RunQuery: instance Opaleye.Internal.RunQuery.QueryRunnerColumnDefault Opaleye.PGTypes.PGTime Data.Time.LocalTime.TimeOfDay.TimeOfDay
- Opaleye.Internal.RunQuery: instance Opaleye.Internal.RunQuery.QueryRunnerColumnDefault Opaleye.PGTypes.PGTimestamp Data.Time.LocalTime.LocalTime.LocalTime
- Opaleye.Internal.RunQuery: instance Opaleye.Internal.RunQuery.QueryRunnerColumnDefault Opaleye.PGTypes.PGTimestamptz Data.Time.Clock.UTC.UTCTime
- Opaleye.Internal.Unpackspec: instance Data.Profunctor.Product.SumProfunctor Opaleye.Internal.Unpackspec.Unpackspec
+ Opaleye.Constant: instance Data.Profunctor.Product.Class.SumProfunctor Opaleye.Constant.Constant
+ Opaleye.Constant: instance Data.Profunctor.Product.Default.Class.Default Opaleye.Constant.Constant (Database.PostgreSQL.Simple.Range.PGRange Data.Time.Clock.Internal.UTCTime.UTCTime) (Opaleye.Internal.Column.Column (Opaleye.PGTypes.PGRange Opaleye.PGTypes.PGTimestamptz))
+ Opaleye.Constant: instance Data.Profunctor.Product.Default.Class.Default Opaleye.Constant.Constant (Database.PostgreSQL.Simple.Range.PGRange Data.Time.LocalTime.Internal.LocalTime.LocalTime) (Opaleye.Internal.Column.Column (Opaleye.PGTypes.PGRange Opaleye.PGTypes.PGTimestamp))
+ Opaleye.Constant: instance Data.Profunctor.Product.Default.Class.Default Opaleye.Constant.Constant Data.Time.Clock.Internal.UTCTime.UTCTime (Opaleye.Internal.Column.Column Opaleye.PGTypes.PGTimestamptz)
+ Opaleye.Constant: instance Data.Profunctor.Product.Default.Class.Default Opaleye.Constant.Constant Data.Time.LocalTime.Internal.LocalTime.LocalTime (Opaleye.Internal.Column.Column Opaleye.PGTypes.PGTimestamp)
+ Opaleye.Constant: instance Data.Profunctor.Product.Default.Class.Default Opaleye.Constant.Constant Data.Time.LocalTime.Internal.TimeOfDay.TimeOfDay (Opaleye.Internal.Column.Column Opaleye.PGTypes.PGTime)
+ Opaleye.Constant: instance Data.Profunctor.Product.Default.Class.Default Opaleye.Constant.Constant Data.Time.LocalTime.Internal.ZonedTime.ZonedTime (Opaleye.Internal.Column.Column Opaleye.PGTypes.PGTimestamptz)
+ Opaleye.Internal.Aggregate: instance Data.Profunctor.Product.Class.SumProfunctor Opaleye.Internal.Aggregate.Aggregator
+ Opaleye.Internal.Distinct: instance Data.Profunctor.Product.Class.SumProfunctor Opaleye.Internal.Distinct.Distinctspec
+ Opaleye.Internal.PackMap: instance Data.Profunctor.Product.Class.SumProfunctor (Opaleye.Internal.PackMap.PackMap a b)
+ Opaleye.Internal.QueryArr: instance Control.Arrow.ArrowChoice Opaleye.Internal.QueryArr.QueryArr
+ Opaleye.Internal.RunQuery: instance Data.Profunctor.Product.Class.SumProfunctor Opaleye.Internal.RunQuery.QueryRunner
+ Opaleye.Internal.RunQuery: instance Opaleye.Internal.RunQuery.QueryRunnerColumnDefault Opaleye.PGTypes.PGTime Data.Time.LocalTime.Internal.TimeOfDay.TimeOfDay
+ Opaleye.Internal.RunQuery: instance Opaleye.Internal.RunQuery.QueryRunnerColumnDefault Opaleye.PGTypes.PGTimestamp Data.Time.LocalTime.Internal.LocalTime.LocalTime
+ Opaleye.Internal.RunQuery: instance Opaleye.Internal.RunQuery.QueryRunnerColumnDefault Opaleye.PGTypes.PGTimestamptz Data.Time.Clock.Internal.UTCTime.UTCTime
+ Opaleye.Internal.RunQuery: instance Opaleye.Internal.RunQuery.QueryRunnerColumnDefault Opaleye.PGTypes.PGTimestamptz Data.Time.LocalTime.Internal.ZonedTime.ZonedTime
+ Opaleye.Internal.Unpackspec: instance Data.Profunctor.Product.Class.SumProfunctor Opaleye.Internal.Unpackspec.Unpackspec
+ Opaleye.PGTypes: pgZonedTime :: ZonedTime -> Column PGTimestamptz
- Opaleye.Internal.HaskellDB.PrimQuery: RangeExpr :: BoundExpr -> BoundExpr -> PrimExpr
+ Opaleye.Internal.HaskellDB.PrimQuery: RangeExpr :: String -> BoundExpr -> BoundExpr -> PrimExpr
- Opaleye.Internal.HaskellDB.Sql: RangeSqlExpr :: SqlRangeBound -> SqlRangeBound -> SqlExpr
+ Opaleye.Internal.HaskellDB.Sql: RangeSqlExpr :: String -> SqlRangeBound -> SqlRangeBound -> SqlExpr
- Opaleye.Internal.Table: class TableColumn a b | a -> b
+ Opaleye.Internal.Table: class TableColumn writeType sqlType | writeType -> sqlType
- Opaleye.Internal.Table: tableColumn :: TableColumn a b => String -> TableColumns a (Column b)
+ Opaleye.Internal.Table: tableColumn :: TableColumn writeType sqlType => String -> TableColumns writeType (Column sqlType)
- Opaleye.PGTypes: class IsSqlType pgType where showPGType = showSqlType showSqlType = showPGType
+ Opaleye.PGTypes: class IsSqlType pgType
- Opaleye.Table: tableColumn :: TableColumn a b => String -> TableColumns a (Column b)
+ Opaleye.Table: tableColumn :: TableColumn writeType sqlType => String -> TableColumns writeType (Column sqlType)

Files

CHANGELOG.md view
@@ -1,3 +1,9 @@+## 0.6.1.0++* Added `ZonedTime` to `PGTimestamptz` mappings++* `ArrowChoice` instance for `QueryArr`+ ## 0.6.0.0  * Added `runUpdateEasy`
Doc/Tutorial/TutorialBasic.lhs view
@@ -136,7 +136,7 @@  You don't have to use Template Haskell, but it just saves us writing things out by hand here.  If you want to avoid Template Haskell see-[Data.Profunctor.Product.TH](https://hackage.haskell.org/package/product-profunctors-0.6.3.1/docs/Data-Profunctor-Product-TH.html).+[Data.Profunctor.Product.TH](https://hackage.haskell.org/package/product-profunctors/docs/Data-Profunctor-Product-TH.html).  Then we can use 'table' to make a table on our record type in exactly the same way as before.
LICENSE view
@@ -1,4 +1,4 @@-Copyright (c) 2014-2017 Purely Agile Limited+Copyright (c) 2014-2018 Purely Agile Limited  All rights reserved. 
README.md view
@@ -1,4 +1,4 @@-# Brief introduction to Opaleye [![Hackage version](https://img.shields.io/hackage/v/opaleye.svg?label=Hackage)](https://hackage.haskell.org/package/opaleye) [![Linux Build Status](https://img.shields.io/travis/tomjaguarpaw/haskell-opaleye.svg?label=Linux%20build)](https://travis-ci.org/tomjaguarpaw/haskell-opaleye)+# Brief introduction to Opaleye [![Hackage version](https://img.shields.io/hackage/v/opaleye.svg?label=Hackage)](https://hackage.haskell.org/package/opaleye) [![Linux Build Status](https://img.shields.io/travis/tomjaguarpaw/haskell-opaleye/master.svg?label=Linux%20build)](https://travis-ci.org/tomjaguarpaw/haskell-opaleye)  Opaleye is a Haskell library that provides an SQL-generating embedded domain specific language for targeting Postgres.  You need Opaleye if@@ -98,8 +98,8 @@ Bjorn Bringert, Anders Hockersten, Torbjorn Martin, Jeremy Shaw and Justin Bailey. -The following individuals and organisations have made helpful-contributions:+The following individuals and organisations made helpful contributions+which were important in helping to get the project off the ground.  * Silk (Erik Hesselink, Adam Bergmark) * Karamaan (Christopher Lewis)@@ -109,4 +109,6 @@ * Travis Staton  Joseph Abrahamson, Alfredo Di Napoli and Mietek Bak performed useful-reviews of early versions which helped improve the codebase.+reviews of early versions which helped improve the codebase.  Since+then there have been helpful contributions from many others.  Thanks+to them all for their help.
Test/Test.hs view
@@ -786,6 +786,14 @@         expected :: [Maybe T.Text]         expected = [Just "21"] +-- Special Test for Github Issue #350 : https://github.com/tomjaguarpaw/haskell-opaleye/issues/350+testRestrictWithJsonOp :: (O.PGIsJson a) => Query (Column a) -> Test+testRestrictWithJsonOp dataQuery = it "restricts the rows returned by checking equality with a value extracted using JSON operator" $ testH query (`shouldBe` table8data)+  where query = dataQuery >>> proc col1 -> do+          t <- table8Q -< ()+          O.restrict -< (O.toNullable col1 O..->> O.pgStrictText "c") .== O.toNullable (O.pgStrictText "21")+          Arr.returnA -< t+ -- Test opaleye's equivalent of c1->'a'->2 testJsonGetArrayValue :: (O.PGIsJson a, O.QueryRunnerColumnDefault a Json.Value) => Query (Column a) -> Test testJsonGetArrayValue dataQuery = it "" $ testH q (`shouldBe` expected)@@ -870,6 +878,18 @@         range a b = O.pgRange O.pgInt4 (R.Inclusive a) (R.Inclusive b)         q = A.pure $ (range 3 7) `O.overlap` (range 4 12) +testRangeDateOverlap :: Test+testRangeDateOverlap = it "generates time overlap" $ \conn -> do+    let date       = Time.fromGregorian 2015 1 1+        now        = Time.UTCTime date (Time.secondsToDiffTime 3600)+        later      = Time.addUTCTime 10 now+        range1     = O.pgRange O.pgUTCTime (R.Inclusive now) (R.Exclusive later)+        range2     = O.pgRange O.pgUTCTime R.NegInfinity R.PosInfinity+        rangeNow   = O.pgRange O.pgUTCTime (R.Inclusive now) (R.Inclusive now)+        qOverlap r = A.pure $ r `O.overlap` rangeNow+    testH (qOverlap range1) (`shouldBe` [True]) conn+    testH (qOverlap range2) (`shouldBe` [True]) conn+ testRangeLeftOf :: Test testRangeLeftOf = it "generates 'left of'" $ testH q (`shouldBe` [True])   where range :: Int -> Int -> Column (O.PGRange O.PGInt4)@@ -1015,6 +1035,7 @@         testJsonGetArrayText    table8Q         testJsonGetPathValue    table8Q         testJsonGetPathText     table8Q+        testRestrictWithJsonOp  table8Q       describe "uncat" $ do         testKeywordColNames         testInsertSerial@@ -1027,6 +1048,7 @@         testUpdate       describe "range" $ do         testRangeOverlap+        testRangeDateOverlap         testRangeLeftOf         testRangeRightOf         testRangeRightExtension
opaleye.cabal view
@@ -1,6 +1,6 @@ name:            opaleye-copyright:       Copyright (c) 2014-2017 Purely Agile Limited-version:         0.6.0.0+copyright:       Copyright (c) 2014-2018 Purely Agile Limited+version:         0.6.1.0 synopsis:        An SQL-generating DSL targeting PostgreSQL description:     An SQL-generating DSL targeting PostgreSQL.  Allows                  Postgres queries to be written within Haskell in a@@ -28,7 +28,7 @@   default-language: Haskell2010   hs-source-dirs: src   build-depends:-      aeson               >= 0.6     && < 1.3+      aeson               >= 0.6     && < 1.4     , base                >= 4.6     && < 5     , base16-bytestring   >= 0.1.1.6 && < 0.2     , case-insensitive    >= 1.2     && < 1.3@@ -36,7 +36,7 @@     , contravariant       >= 1.2     && < 1.5     , postgresql-simple   >= 0.5.3   && < 0.6     , pretty              >= 1.1.1.0 && < 1.2-    , product-profunctors >= 0.6.2   && < 0.9+    , product-profunctors >= 0.6.2   && < 0.10     , profunctors         >= 4.0     && < 5.3     , semigroups          >= 0.13    && < 0.19     , text                >= 0.11    && < 1.3
src/Opaleye/Aggregate.hs view
@@ -53,7 +53,7 @@  {-| Given a 'Query' producing rows of type @a@ and an 'Aggregator' accepting rows of-type @a@, apply the aggregator to the results of the query.+type @a@, apply the aggregator to the query.  If you simply want to count the number of rows in a query you might find the 'countRows' function more convenient.
src/Opaleye/Column.hs view
@@ -49,7 +49,8 @@ -- | If the @Column (Nullable a)@ is NULL then return the provided -- @Column a@ otherwise return the underlying @Column a@. ----- The Opaleye equivalent of 'Data.Maybe.fromMaybe'.+-- The Opaleye equivalent of 'Data.Maybe.fromMaybe' and very similar+-- to PostgreSQL's @COALESCE@. fromNullable :: Column a -> Column (Nullable a) -> Column a fromNullable = flip matchNullable id 
src/Opaleye/Constant.hs view
@@ -100,6 +100,9 @@ instance D.Default Constant Time.LocalTime (Column T.PGTimestamp) where   def = Constant T.pgLocalTime +instance D.Default Constant Time.ZonedTime (Column T.PGTimestamptz) where+  def = Constant T.pgZonedTime+ instance D.Default Constant Time.TimeOfDay (Column T.PGTime) where   def = Constant T.pgTimeOfDay 
src/Opaleye/Internal/Aggregate.hs view
@@ -25,7 +25,7 @@ An 'Aggregator' corresponds closely to a 'Control.Foldl.Fold' from the @foldl@ package.  Whereas an 'Aggregator' @a@ @b@ takes each group of type @a@ to a single row of type @b@, a 'Control.Foldl.Fold' @a@ @b@-takes a list of @a@ and returns a single row of type @b@.+takes a list of @a@ and returns a single value of type @b@. -} newtype Aggregator a b = Aggregator                          (PM.PackMap (Maybe (HPQ.AggrOp, [HPQ.OrderExpr],HPQ.AggrDistinct), HPQ.PrimExpr)
src/Opaleye/Internal/HaskellDB/PrimQuery.hs view
@@ -34,7 +34,7 @@                                     -- here.  Perhaps a special type is                                     -- needed for insert expressions.                 | ArrayExpr [PrimExpr] -- ^ ARRAY[..]-                | RangeExpr BoundExpr BoundExpr+                | RangeExpr String BoundExpr BoundExpr                 | ArrayIndex PrimExpr PrimExpr                 deriving (Read,Show) 
src/Opaleye/Internal/HaskellDB/Sql.hs view
@@ -55,7 +55,7 @@              | CastSqlExpr String SqlExpr              | DefaultSqlExpr              | ArraySqlExpr [SqlExpr]-             | RangeSqlExpr SqlRangeBound SqlRangeBound+             | RangeSqlExpr String SqlRangeBound SqlRangeBound   deriving Show  -- | Data type for SQL UPDATE statements.
src/Opaleye/Internal/HaskellDB/Sql/Default.hs view
@@ -115,7 +115,7 @@                            in case t of                                 UnOpFun     -> FunSqlExpr op' [e']                                 UnOpPrefix  -> PrefixSqlExpr op' (ParensSqlExpr e')-                                UnOpPostfix -> PostfixSqlExpr op' e'+                                UnOpPostfix -> PostfixSqlExpr op' (ParensSqlExpr e')       -- TODO: The current arrangement whereby the delimeter parameter       -- of string_agg is in the AggrStringAggr constructor, but the       -- parameter being aggregated is not, seems unsatisfactory@@ -144,12 +144,12 @@       CastExpr typ e1 -> CastSqlExpr typ (sqlExpr gen e1)       DefaultInsertExpr -> DefaultSqlExpr       ArrayExpr es -> ArraySqlExpr (map (sqlExpr gen) es)-      RangeExpr l r -> let bound :: PQ.BoundExpr -> Sql.SqlRangeBound-                           bound (PQ.Inclusive a) = Sql.Inclusive (sqlExpr gen a)-                           bound (PQ.Exclusive a) = Sql.Exclusive (sqlExpr gen a)-                           bound PQ.PosInfinity   = Sql.PosInfinity-                           bound PQ.NegInfinity   = Sql.NegInfinity-                        in RangeSqlExpr (bound l) (bound r)+      RangeExpr t l r -> let bound :: PQ.BoundExpr -> Sql.SqlRangeBound+                             bound (PQ.Inclusive a) = Sql.Inclusive (sqlExpr gen a)+                             bound (PQ.Exclusive a) = Sql.Exclusive (sqlExpr gen a)+                             bound PQ.PosInfinity   = Sql.PosInfinity+                             bound PQ.NegInfinity   = Sql.NegInfinity+                        in RangeSqlExpr t (bound l) (bound r)       ArrayIndex e1 e2 -> SubscriptSqlExpr (ParensSqlExpr $ sqlExpr gen e1) (ParensSqlExpr $ sqlExpr gen e2)  showBinOp :: BinOp -> String
src/Opaleye/Internal/HaskellDB/Sql/Print.hs view
@@ -2,6 +2,8 @@ --                HWT Group (c) 2003, haskelldb-users@lists.sourceforge.net -- License     :  BSD-style +{-# LANGUAGE LambdaCase #-}+ module Opaleye.Internal.HaskellDB.Sql.Print (                                      deliteral,                                      ppUpdate,@@ -117,18 +119,34 @@   where     tname = doubleQuotes (text (sqlTableName st)) -ppStartBound :: SqlRangeBound -> Doc-ppStartBound (Inclusive a) = text "'[" <> ppSqlExpr a-ppStartBound (Exclusive a) = text "'(" <> ppSqlExpr a-ppStartBound PosInfinity   = text "'(infinity"-ppStartBound NegInfinity   = text "'(-infinity"+data InclusiveExclusive = Inclusive' | Exclusive' -ppEndBound :: SqlRangeBound -> Doc-ppEndBound (Inclusive a) = ppSqlExpr a <> text "]'"-ppEndBound (Exclusive a) = ppSqlExpr a <> text ")'"-ppEndBound PosInfinity   = text "infinity)'"-ppEndBound NegInfinity   = text "-infinity)'"+ppRange :: String -> SqlRangeBound -> SqlRangeBound -> Doc+ppRange t start end =+  ppSqlExpr (FunSqlExpr t [ startValue+                          , endValue+                          , ConstSqlExpr boundTypeSymbol+                          ]) +  where value_boundTypeT = \case+          Inclusive a -> (Inclusive', a)+          Exclusive a -> (Exclusive', a)+          PosInfinity -> (Exclusive', ConstSqlExpr "'infinity'")+          NegInfinity -> (Exclusive', ConstSqlExpr "'-infinity'")++        (startType, startValue) = value_boundTypeT start+        (endType,   endValue)   = value_boundTypeT end++        startTypeSymbol = case startType of+          Inclusive' -> "["+          Exclusive' -> "("++        endTypeSymbol = case endType of+          Inclusive' -> "]"+          Exclusive' -> ")"++        boundTypeSymbol = "'" ++ startTypeSymbol ++ endTypeSymbol ++ "'"+ ppSqlExpr :: SqlExpr -> Doc ppSqlExpr expr =     case expr of@@ -147,7 +165,7 @@       CastSqlExpr typ e      -> text "CAST" <> parens (ppSqlExpr e <+> text "AS" <+> text typ)       DefaultSqlExpr         -> text "DEFAULT"       ArraySqlExpr es        -> text "ARRAY" <> brackets (commaH ppSqlExpr es)-      RangeSqlExpr start end -> (hcat . punctuate comma) [ppStartBound start, ppEndBound end]+      RangeSqlExpr t s e     -> ppRange t s e       AggrFunSqlExpr f es ord distinct -> text f <> parens (ppSqlDistinct distinct <+> commaH ppSqlExpr es <+> ppOrderBy ord)       CaseSqlExpr cs el   -> text "CASE" <+> vcat (toList (fmap ppWhen cs))                              <+> text "ELSE" <+> ppSqlExpr el <+> text "END"
src/Opaleye/Internal/Order.hs view
@@ -71,9 +71,9 @@ -- of input columns. Note that this list does not have to contain an entry for -- every result in your query: you may exactly order only a subset of results, -- if you wish. Rows that are not ordered according to the input list are--- returned __after__ the ordered results, in the usual order the database would+-- returned /after/ the ordered results, in the usual order the database would -- return them (e.g. sorted by primary key). Exactly-ordered results always come--- first in a result set. Entries in the input list that are __not__ present in+-- first in a result set. Entries in the input list that are /not/ present in -- result of a query are ignored. exact :: [IC.Column b] -> (a -> IC.Column b) -> Order a exact xs k = maybe M.mempty go (NL.nonEmpty xs) where
src/Opaleye/Internal/QueryArr.hs view
@@ -62,6 +62,12 @@     where g ((b, d), primQ, t0) = ((c, d), primQ', t1)             where (c, primQ', t1) = runQueryArr f (b, primQ, t0) +instance Arr.ArrowChoice QueryArr where+  left f = QueryArr g+    where g (e, primQ, t0) = case e of+            Left a -> first3 Left (runQueryArr f (a, primQ, t0))+            Right b -> (Right b, primQ, t0)+ instance Functor (QueryArr a) where   fmap f = (arr f <<<) 
src/Opaleye/Internal/RunQuery.hs view
@@ -201,6 +201,9 @@ instance QueryRunnerColumnDefault T.PGTimestamp Time.LocalTime where   queryRunnerColumnDefault = fieldQueryRunnerColumn +instance QueryRunnerColumnDefault T.PGTimestamptz Time.ZonedTime where+  queryRunnerColumnDefault = fieldQueryRunnerColumn+ instance QueryRunnerColumnDefault T.PGTime Time.TimeOfDay where   queryRunnerColumnDefault = fieldQueryRunnerColumn 
src/Opaleye/Internal/Table.hs view
@@ -122,11 +122,12 @@   (optionalW columnName)   (View (Column (HPQ.BaseTableAttrExpr columnName))) -class TableColumn a b | a -> b where-    -- | Create either a 'required' or 'optional' column depending on+class TableColumn writeType sqlType | writeType -> sqlType where+    -- | Infer either a 'required' or 'optional' column depending on     -- the write type.  It's generally more convenient to use this-    -- than 'required' or 'optional'.-    tableColumn :: String -> TableColumns a (Column b)+    -- than 'required' or 'optional' but you do have to provide a type+    -- signature instead.+    tableColumn :: String -> TableColumns writeType (Column sqlType)  instance TableColumn (Column a) a where     tableColumn = required
src/Opaleye/Manipulation.hs view
@@ -4,7 +4,7 @@  -- | Inserts, updates and deletes ----- Please note that you currently you can only INSERT or UPDATE with+-- Please note that Opaleye currently only supports INSERT or UPDATE with -- constant values, not the result of SELECTS.  That is, you can -- generate SQL of the form --
src/Opaleye/Operators.hs view
@@ -30,9 +30,16 @@  -- * Restriction operators -{-| Restrict query results to a particular condition.  Corresponds to-the guard method of the MonadPlus class.  You would typically use-'restrict' if you want to use 'A.Arrow' notation.  -}+{-| Keep only the rows of a query satisfying a given condition, using+an SQL @WHERE@ clause.++You would typically use 'restrict' if you want to write your query+using 'A.Arrow' notation.  If you want to use a "point free" style+then 'keepWhen' will suit you better.++(If you are familiar with 'Control.Monad.MonadPlus' or+'Control.Applicative.Alternative' it may help you to know that+'restrict' corresponds to the 'Control.Monad.guard' function.) -} restrict :: QueryArr (Column T.PGBool) () restrict = QueryArr f where   f (Column predicate, primQ, t0) = ((), PQ.restrict predicate primQ, t0)@@ -49,10 +56,16 @@   f (a, primQ, t0) = ((), PQ.notExists primQ existsQ, t1) where     (_, existsQ, t1) = runSimpleQueryArr criteria (a, t0) -{-| Filter a 'QueryArr' to only those rows where the given condition-holds.  This is the 'QueryArr' equivalent of 'Prelude.filter' from the-'Prelude'.  You would typically use 'keepWhen' if you want to use a-\"point free\" style.-}+{-| Keep only the rows of a query satisfying a given condition, using+an SQL @WHERE@ clause.++You would typically use 'keepWhen' if you want to write+your query using a "point free" style.  If you want to use 'A.Arrow'+notation then 'restrict' will suit you better.++This is the 'QueryArr' equivalent of 'Prelude.filter' from the+'Prelude'.+-} keepWhen :: (a -> Column T.PGBool) -> QueryArr a a keepWhen p = proc a -> do   restrict  -< p a@@ -102,16 +115,20 @@  -- * Numerical operators +-- | Integral division, named after 'Prelude.quot'.  It maps to the+-- @/@ operator in Postgres. quot_ :: C.PGIntegral a => Column a -> Column a -> Column a quot_ = C.binOp (HPQ.:/) --- | The remainder of division named after 'Prelude.rem'.--- It maps to 'MOD' ('%') in Postgres, confusingly described as "modulo (remainder)".+-- | The remainder of integral division, named after 'Prelude.rem'.+-- It maps to 'MOD' ('%') in Postgres, confusingly described as+-- "modulo (remainder)". rem_ :: C.PGIntegral a => Column a -> Column a -> Column a rem_ = C.binOp HPQ.OpMod  -- * Conditional operators +-- | Select the first case for which the condition is true. case_ :: [(Column T.PGBool, Column a)] -> Column a -> Column a case_ = unsafeCase_ @@ -221,7 +238,6 @@ -- * JSON operators  -- | Class of Postgres types that represent json values.--- -- Used to overload functions and operators that work on both 'T.PGJson' and 'T.PGJsonb'. -- -- Warning: making additional instances of this class can lead to broken code!@@ -296,7 +312,7 @@ (.?&) :: Column T.PGJsonb -> Column (T.PGArray T.PGText) -> Column T.PGBool (.?&) = C.binOp (HPQ.:?&) --- * PGArray Operators+-- * PGArray operators  emptyArray :: T.IsSqlType a => Column (T.PGArray a) emptyArray = T.pgArray id []@@ -310,18 +326,7 @@ index :: (C.PGIntegral n) => Column (T.PGArray a) -> Column n -> Column (C.Nullable a) index (Column a) (Column b) = Column (HPQ.ArrayIndex a b) --- * Other operators--timestamptzAtTimeZone :: Column T.PGTimestamptz-                      -> Column T.PGText-                      -> Column T.PGTimestamp-timestamptzAtTimeZone = C.binOp HPQ.OpAtTimeZone--{-# DEPRECATED doubleOfInt-    "Use 'C.unsafeCast' instead. \-    \Will be removed in version 0.7." #-}-doubleOfInt :: Column T.PGInt4 -> Column T.PGFloat8-doubleOfInt (Column e) = Column (HPQ.CastExpr "float8" e)+-- * Range operators  overlap :: Column (T.PGRange a) -> Column (T.PGRange a) -> Column T.PGBool overlap = C.binOp (HPQ.:&&)@@ -346,12 +351,25 @@ (.-|-) :: Column (T.PGRange a) -> Column (T.PGRange a) -> Column T.PGBool (.-|-) = C.binOp (HPQ.:-|-) +-- * Other operators++timestamptzAtTimeZone :: Column T.PGTimestamptz+                      -> Column T.PGText+                      -> Column T.PGTimestamp+timestamptzAtTimeZone = C.binOp HPQ.OpAtTimeZone+ -- * Deprecated +{-# DEPRECATED doubleOfInt+    "Use 'C.unsafeCast' instead. \+    \Will be removed in version 0.7." #-}+doubleOfInt :: Column T.PGInt4 -> Column T.PGFloat8+doubleOfInt (Column e) = Column (HPQ.CastExpr "float8" e)+ -- | Identical to 'restrictExists'.  Will be deprecated in version 0.7. exists :: QueryArr a b -> QueryArr a () exists = restrictExists --- | Identical to 'restrictNoExists'.  Will be deprecated in version 0.7.+-- | Identical to 'restrictNotExists'.  Will be deprecated in version 0.7. notExists :: QueryArr a b -> QueryArr a () notExists = restrictNotExists
src/Opaleye/Order.hs view
@@ -72,6 +72,29 @@ {- | Limit the results of the given query to the given maximum number of items.++/WARNING:/ If you're planning on using limit/offset together please use+'offset' /before/ you use 'limit', e.g.:++@+limit 10 (offset 50 yourQuery)+@++This is because Opaleye applies OFFSET and LIMIT to the query separately.+The result of the query given above is the following, which will return+10 rows after skipping the first 50 (probably what you want).++@+SELECT * FROM (SELECT * FROM yourTable OFFSET 50) LIMIT 10+@++However, reversing the order of the limit\/offset will result in the+following, which will result in /no rows being returned/ (probably+not what you want).++@+SELECT * FROM (SELECT * FROM yourTable LIMIT 10) OFFSET 50+@ -} limit :: Int -> Query a -> Query a limit n a = Q.simpleQueryArr (O.limit' n . Q.runSimpleQueryArr a)@@ -79,6 +102,9 @@ {- | Offset the results of the given query by the given amount, skipping that many result rows.++/WARNING:/ Please read the documentation of 'limit' before combining+'offset' with 'limit'. -} offset :: Int -> Query a -> Query a offset n a = Q.simpleQueryArr (O.offset' n . Q.runSimpleQueryArr a)
src/Opaleye/PGTypes.hs view
@@ -89,6 +89,9 @@ pgLocalTime :: Time.LocalTime -> Column PGTimestamp pgLocalTime = IPT.unsafePgFormatTime "timestamp" "'%FT%T%Q'" +pgZonedTime :: Time.ZonedTime -> Column PGTimestamptz+pgZonedTime = IPT.unsafePgFormatTime "timestamptz" "'%FT%T%Q%z'"+ pgTimeOfDay :: Time.TimeOfDay -> Column PGTime pgTimeOfDay = IPT.unsafePgFormatTime "time" "'%T%Q'" @@ -143,14 +146,14 @@     arrayTy = showSqlType ([] :: [PGArray b])  pgRange :: forall a b. IsRangeType b => (a -> C.Column b) -> R.RangeBound a -> R.RangeBound a -> C.Column (PGRange b)-pgRange pgEl start end = C.Column (HPQ.CastExpr (showRangeType ([] :: [b])) $ HPQ.RangeExpr (oneEl start) (oneEl end))+pgRange pgEl start end = C.Column (HPQ.RangeExpr (showRangeType ([] :: [b])) (oneEl start) (oneEl end))   where oneEl (R.Inclusive a) = HPQ.Inclusive . C.unColumn $ pgEl a         oneEl (R.Exclusive a) = HPQ.Exclusive . C.unColumn $ pgEl a         oneEl R.NegInfinity   = HPQ.NegInfinity         oneEl R.PosInfinity   = HPQ.PosInfinity  {-# DEPRECATED showPGType-    "Use 'showSqlType' instead. 'showSqlType' will be deprecated \+    "Use 'showSqlType' instead. 'showPGType' will be removed \     \in version 0.7." #-} class IsSqlType pgType where   showPGType :: proxy pgType -> String