relational-query 0.12.0.1 → 0.12.1.0
raw patch · 9 files changed
+101/−80 lines, 9 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
+ Database.Relational.Pure: instance Database.Relational.ProjectableClass.LiteralSQL GHC.Integer.Type.Integer
+ Database.Relational.Pure: instance Database.Relational.ProjectableClass.LiteralSQL GHC.Types.Word
+ Database.Relational.Pure: instance Database.Relational.ProjectableClass.LiteralSQL GHC.Word.Word16
+ Database.Relational.Pure: instance Database.Relational.ProjectableClass.LiteralSQL GHC.Word.Word32
+ Database.Relational.Pure: instance Database.Relational.ProjectableClass.LiteralSQL GHC.Word.Word64
+ Database.Relational.Pure: instance Database.Relational.ProjectableClass.LiteralSQL GHC.Word.Word8
- Database.Relational.SqlSyntax: type AggregateColumnRef = StringSQL
+ Database.Relational.SqlSyntax: type AggregateColumnRef = Column
- Database.Relational.SqlSyntax: type OrderColumn = StringSQL
+ Database.Relational.SqlSyntax: type OrderColumn = Column
Files
- ChangeLog.md +5/−1
- relational-query.cabal +1/−1
- src/Database/Relational/Monad/Trans/Aggregating.hs +6/−6
- src/Database/Relational/Monad/Trans/Ordering.hs +3/−4
- src/Database/Relational/Pure.hs +25/−0
- src/Database/Relational/SqlSyntax/Aggregate.hs +1/−37
- src/Database/Relational/SqlSyntax/Fold.hs +55/−6
- src/Database/Relational/SqlSyntax/Query.hs +2/−22
- src/Database/Relational/SqlSyntax/Types.hs +3/−3
ChangeLog.md view
@@ -1,8 +1,12 @@ <!-- -*- Markdown -*- --> +## 0.12.1.0++- add LiteralSQL instances of word and integer types.+ ## 0.12.0.1 -- Update missing of this changelog.+- update missing of this changelog. ## 0.12.0.0
relational-query.cabal view
@@ -1,5 +1,5 @@ name: relational-query-version: 0.12.0.1+version: 0.12.1.0 synopsis: Typeful, Modular, Relational, algebraic query engine description: This package contiains typeful relation structure and relational-algebraic query building DSL which can
src/Database/Relational/Monad/Trans/Aggregating.hs view
@@ -4,7 +4,7 @@ -- | -- Module : Database.Relational.Monad.Trans.Aggregating--- Copyright : 2013-2017 Kei Hibino+-- Copyright : 2013-2018 Kei Hibino -- License : BSD3 -- -- Maintainer : ex8k.hibino@gmail.com@@ -39,7 +39,7 @@ import Database.Relational.Internal.ContextType (Flat, Aggregated, Set, Power, SetList) import Database.Relational.SqlSyntax- (Record,+ (Record, untypeRecord, AggregateColumnRef, AggregateElem, aggregateColumnRef, AggregateSet, aggregateGroupingSet, AggregateBitKey, aggregatePowerKey, aggregateRollup, aggregateCube, aggregateSets, AggregateKey, aggregateKeyRecord, aggregateKeyElement, unsafeAggregateKey)@@ -99,13 +99,13 @@ -- | Aggregated query instance. instance MonadQuery m => MonadAggregate (AggregatingSetT m) where groupBy p = do- mapM_ unsafeAggregateWithTerm [ aggregateColumnRef col | col <- Record.columns p]+ mapM_ unsafeAggregateWithTerm [ aggregateColumnRef col | col <- untypeRecord p] return $ Record.unsafeToAggregated p groupBy' = aggregateKey -- | Partition clause instance instance Monad m => MonadPartition c (PartitioningSetT c m) where- partitionBy = mapM_ unsafeAggregateWithTerm . Record.columns+ partitionBy = mapM_ unsafeAggregateWithTerm . untypeRecord -- | Run 'Aggregatings' to get terms list. extractAggregateTerms :: (Monad m, Functor m) => Aggregatings ac at m a -> m (a, [at])@@ -130,7 +130,7 @@ key :: Record Flat r -> AggregatingSet (Record Aggregated (Maybe r)) key p = do- mapM_ unsafeAggregateWithTerm [ aggregateColumnRef col | col <- Record.columns p]+ mapM_ unsafeAggregateWithTerm [ aggregateColumnRef col | col <- untypeRecord p] return . Record.just $ Record.unsafeToAggregated p -- | Specify key of single grouping set.@@ -150,7 +150,7 @@ bkey :: Record Flat r -> AggregatingPowerSet (Record Aggregated (Maybe r)) bkey p = do- unsafeAggregateWithTerm . aggregatePowerKey $ Record.columns p+ unsafeAggregateWithTerm . aggregatePowerKey $ untypeRecord p return . Record.just $ Record.unsafeToAggregated p finalizePower :: ([AggregateBitKey] -> AggregateElem)
src/Database/Relational/Monad/Trans/Ordering.hs view
@@ -5,7 +5,7 @@ -- | -- Module : Database.Relational.Monad.Trans.Ordering--- Copyright : 2013-2017 Kei Hibino+-- Copyright : 2013-2018 Kei Hibino -- License : BSD3 -- -- Maintainer : ex8k.hibino@gmail.com@@ -32,9 +32,8 @@ import Data.DList (DList, toList) import Database.Relational.SqlSyntax- (Order (..), Nulls (..), OrderingTerm, Record)+ (Order (..), Nulls (..), OrderingTerm, Record, untypeRecord) -import qualified Database.Relational.Record as Record import Database.Relational.Monad.Class (MonadQualify (..), MonadRestrict(..), MonadQuery(..), MonadAggregate(..), MonadPartition(..)) @@ -79,7 +78,7 @@ -> Record c t -- ^ Ordering terms to add -> Orderings c m () -- ^ Result context with ordering updateOrderBys opair p = Orderings . mapM_ tell $ terms where- terms = curry pure opair `map` Record.columns p+ terms = curry pure opair `map` untypeRecord p -- | Add ordering terms with null ordering. orderBy' :: Monad m
src/Database/Relational/Pure.hs view
@@ -17,6 +17,7 @@ import Control.Applicative (pure) import Data.Monoid ((<>)) import Data.Int (Int8, Int16, Int32, Int64)+import Data.Word (Word8, Word16, Word32, Word64, Word) import Data.ByteString (ByteString) import qualified Data.ByteString.Lazy as LB import Data.Text (Text)@@ -80,6 +81,30 @@ -- | Constant SQL terms of 'Int'. -- Use this carefully, because this is architecture dependent size of integer type. instance LiteralSQL Int where+ showLiteral' = intTermsSQL++-- | Constant SQL terms of 'Word8'.+instance LiteralSQL Word8 where+ showLiteral' = intTermsSQL++-- | Constant SQL terms of 'Word16'.+instance LiteralSQL Word16 where+ showLiteral' = intTermsSQL++-- | Constant SQL terms of 'Word32'.+instance LiteralSQL Word32 where+ showLiteral' = intTermsSQL++-- | Constant SQL terms of 'Word64'.+instance LiteralSQL Word64 where+ showLiteral' = intTermsSQL++-- | Constant SQL terms of 'Word'.+-- Use this carefully, because this is architecture dependent size of integer type.+instance LiteralSQL Word where+ showLiteral' = intTermsSQL++instance LiteralSQL Integer where showLiteral' = intTermsSQL -- | Constant SQL terms of 'String'.
src/Database/Relational/SqlSyntax/Aggregate.hs view
@@ -1,6 +1,6 @@ -- | -- Module : Database.Relational.SqlSyntax.Aggregate--- Copyright : 2013-2017 Kei Hibino+-- Copyright : 2013-2018 Kei Hibino -- License : BSD3 -- -- Maintainer : ex8k.hibino@gmail.com@@ -13,17 +13,9 @@ aggregatePowerKey, aggregateGroupingSet, aggregateRollup, aggregateCube, aggregateSets, - composeGroupBy, composePartitionBy,- aggregateKeyRecord, aggregateKeyElement, unsafeAggregateKey, ) where -import Data.Monoid (Monoid (..), (<>))--import Language.SQL.Keyword (Keyword(..), (|*|))-import qualified Language.SQL.Keyword as SQL--import Database.Relational.Internal.String (StringSQL) import Database.Relational.SqlSyntax.Types (AggregateBitKey (..), AggregateSet (..), AggregateElem (..), AggregateColumnRef, AggregateKey (..), )@@ -52,34 +44,6 @@ -- | Grouping sets aggregation. aggregateSets :: [AggregateSet] -> AggregateElem aggregateSets = GroupingSets--commaed :: [StringSQL] -> StringSQL-commaed = SQL.fold (|*|)--pComma :: (a -> StringSQL) -> [a] -> StringSQL-pComma qshow = SQL.paren . commaed . map qshow--showsAggregateBitKey :: AggregateBitKey -> StringSQL-showsAggregateBitKey (AggregateBitKey ts) = pComma id ts---- | Compose GROUP BY clause from AggregateElem list.-composeGroupBy :: [AggregateElem] -> StringSQL-composeGroupBy = d where- d [] = mempty- d es@(_:_) = GROUP <> BY <> rec es- keyList op ss = op <> pComma showsAggregateBitKey ss- rec = commaed . map showsE- showsGs (AggregateSet s) = SQL.paren $ rec s- showsE (ColumnRef t) = t- showsE (Rollup ss) = keyList ROLLUP ss- showsE (Cube ss) = keyList CUBE ss- showsE (GroupingSets ss) = GROUPING <> SETS <> pComma showsGs ss---- | Compose PARTITION BY clause from AggregateColumnRef list.-composePartitionBy :: [AggregateColumnRef] -> StringSQL-composePartitionBy = d where- d [] = mempty- d ts@(_:_) = PARTITION <> BY <> commaed ts -- | Extract typed record from 'AggregateKey'. aggregateKeyRecord :: AggregateKey a -> a
src/Database/Relational/SqlSyntax/Fold.hs view
@@ -2,7 +2,7 @@ -- | -- Module : Database.Relational.SqlSyntax.Fold--- Copyright : 2013-2017 Kei Hibino+-- Copyright : 2013-2018 Kei Hibino -- License : BSD3 -- -- Maintainer : ex8k.hibino@gmail.com@@ -26,9 +26,15 @@ recordRawColumns, -- * Query restriction- composeWhere, composeHaving- ) where+ composeWhere, composeHaving, + -- * Aggregation+ composeGroupBy, composePartitionBy,++ -- * Ordering+ composeOrderBy,+) where+ import Control.Applicative ((<$>), pure) import Data.Monoid (mempty, (<>), mconcat) import Data.Traversable (traverse)@@ -43,13 +49,13 @@ import qualified Database.Relational.Internal.UntypedTable as UntypedTable import Database.Relational.Internal.String (StringSQL, stringSQL, rowStringSQL, showStringSQL, boolSQL, )-import Database.Relational.SqlSyntax.Query (composeOrderBy, )-import Database.Relational.SqlSyntax.Aggregate (composeGroupBy, ) import Database.Relational.SqlSyntax.Types (SubQuery (..), Record, Tuple, Predicate, Column (..), CaseClause(..), WhenClauses (..), NodeAttr (Just', Maybe), ProductTree (Leaf, Join), JoinProduct,- Duplication (..), SetOp (..), BinOp (..), Qualifier (..), Qualified (..), )+ Duplication (..), SetOp (..), BinOp (..), Qualifier (..), Qualified (..),+ AggregateBitKey (..), AggregateSet (..), AggregateElem (..), AggregateColumnRef,+ Order (..), Nulls (..), OrderingTerm, ) import qualified Database.Relational.SqlSyntax.Types as Syntax @@ -268,3 +274,46 @@ -- | Compose HAVING clause from 'QueryRestriction'. composeHaving :: [Predicate Aggregated] -> StringSQL composeHaving = composeRestrict HAVING++-----++commaed :: [StringSQL] -> StringSQL+commaed = SQL.fold (|*|)++pComma :: (a -> StringSQL) -> [a] -> StringSQL+pComma qshow = SQL.paren . commaed . map qshow++showsAggregateBitKey :: AggregateBitKey -> StringSQL+showsAggregateBitKey (AggregateBitKey ts) = pComma id $ map showColumn ts++-- | Compose GROUP BY clause from AggregateElem list.+composeGroupBy :: [AggregateElem] -> StringSQL+composeGroupBy = d where+ d [] = mempty+ d es@(_:_) = GROUP <> BY <> rec es+ keyList op ss = op <> pComma showsAggregateBitKey ss+ rec = commaed . map showsE+ showsGs (AggregateSet s) = SQL.paren $ rec s+ showsE (ColumnRef t) = showColumn t+ showsE (Rollup ss) = keyList ROLLUP ss+ showsE (Cube ss) = keyList CUBE ss+ showsE (GroupingSets ss) = GROUPING <> SETS <> pComma showsGs ss++-- | Compose PARTITION BY clause from AggregateColumnRef list.+composePartitionBy :: [AggregateColumnRef] -> StringSQL+composePartitionBy = d where+ d [] = mempty+ d ts@(_:_) = PARTITION <> BY <> commaed (map showColumn ts)++-----++-- | Compose ORDER BY clause from OrderingTerms+composeOrderBy :: [OrderingTerm] -> StringSQL+composeOrderBy = d where+ d [] = mempty+ d ts@(_:_) = ORDER <> BY <> SQL.fold (|*|) (map showsOt ts)+ showsOt ((o, mn), e) = showColumn e <> order o <> maybe mempty ((NULLS <>) . nulls) mn+ order Asc = ASC+ order Desc = DESC+ nulls NullsFirst = FIRST+ nulls NullsLast = LAST
src/Database/Relational/SqlSyntax/Query.hs view
@@ -1,6 +1,6 @@ -- | -- Module : Database.Relational.SqlSyntax.Query--- Copyright : 2013-2017 Kei Hibino+-- Copyright : 2013-2018 Kei Hibino -- License : BSD3 -- -- Maintainer : ex8k.hibino@gmail.com@@ -12,21 +12,13 @@ flatSubQuery, aggregatedSubQuery, union, except, intersect, caseSearch, case',-- composeOrderBy, ) where -import Data.Monoid (mempty, (<>))--import Language.SQL.Keyword (Keyword(..), (|*|))-import qualified Language.SQL.Keyword as SQL- import Database.Relational.Internal.Config (Config) import Database.Relational.Internal.ContextType (Flat, Aggregated)-import Database.Relational.Internal.String (StringSQL) import Database.Relational.SqlSyntax.Types (Duplication (..), SetOp (..), BinOp (..),- Order (..), Nulls (..), OrderingTerm, AggregateElem,+ OrderingTerm, AggregateElem, JoinProduct, Predicate, WhenClauses (..), CaseClause (..), SubQuery (..), Column (..), Tuple, Record, record, untypeRecord, recordWidth, ) @@ -100,15 +92,3 @@ record [ Case c i | i <- [0 .. recordWidth e - 1] ] where c = CaseSimple (untypeRecord v) $ whenClauses "case'" ws e----- | Compose ORDER BY clause from OrderingTerms-composeOrderBy :: [OrderingTerm] -> StringSQL-composeOrderBy = d where- d [] = mempty- d ts@(_:_) = ORDER <> BY <> SQL.fold (|*|) (map showsOt ts)- showsOt ((o, mn), e) = e <> order o <> maybe mempty ((NULLS <>) . nulls) mn- order Asc = ASC- order Desc = DESC- nulls NullsFirst = FIRST- nulls NullsLast = LAST
src/Database/Relational/SqlSyntax/Types.hs view
@@ -2,7 +2,7 @@ -- | -- Module : Database.Relational.SqlSyntax.Types--- Copyright : 2015-2017 Kei Hibino+-- Copyright : 2015-2018 Kei Hibino -- License : BSD3 -- -- Maintainer : ex8k.hibino@gmail.com@@ -74,13 +74,13 @@ data Nulls = NullsFirst | NullsLast deriving Show -- | Type for order-by column-type OrderColumn = StringSQL+type OrderColumn = Column -- | Type for order-by term type OrderingTerm = ((Order, Maybe Nulls), OrderColumn) -- | Type for group-by term-type AggregateColumnRef = StringSQL+type AggregateColumnRef = Column -- | Type for group key. newtype AggregateBitKey = AggregateBitKey [AggregateColumnRef] deriving Show