packages feed

esqueleto 3.1.1 → 3.1.2

raw patch · 3 files changed

+35/−2 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Database.Esqueleto: associateJoin :: forall e1 e0. Ord (Key e0) => [(Entity e0, e1)] -> Map (Key e0) (e0, [e1])

Files

changelog.md view
@@ -1,3 +1,9 @@+3.1.2+========++- @tippenein+  - [#149](https://github.com/bitemyapp/esqueleto/pull/157): Added `associateJoin` query helpers.+ 3.1.1 ======== 
esqueleto.cabal view
@@ -1,7 +1,7 @@ cabal-version: 1.12  name:           esqueleto-version:        3.1.1+version:        3.1.2 synopsis:       Type-safe EDSL for SQL queries on persistent backends. description:    @esqueleto@ is a bare bones, type-safe EDSL for SQL queries that works with unmodified @persistent@ SQL backends.  Its language closely resembles SQL, so you don't have to learn new concepts, just new syntax, and it's fairly easy to predict the generated SQL and optimize it for your backend. Most kinds of errors committed when writing SQL are caught as compile-time errors---although it is possible to write type-checked @esqueleto@ queries that fail at runtime.                 .@@ -47,6 +47,7 @@     , aeson >=1.0     , blaze-html     , bytestring+    , containers     , conduit >=1.3     , monad-logger     , persistent >=2.10.0 && <2.11
src/Database/Esqueleto.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE FlexibleContexts, FlexibleInstances, GADTs #-}+{-# LANGUAGE FlexibleContexts, FlexibleInstances, GADTs, RankNTypes #-} -- | The @esqueleto@ EDSL (embedded domain specific language). -- This module replaces @Database.Persist@, so instead of -- importing that module you should just import this one:@@ -100,6 +100,7 @@     -- * Helpers   , valkey   , valJ+  , associateJoin      -- * Re-exports     -- $reexports@@ -110,6 +111,7 @@ import Control.Monad.IO.Class (MonadIO) import Control.Monad.Trans.Reader (ReaderT) import Data.Int (Int64)+import qualified Data.Map.Strict as Map import Database.Esqueleto.Internal.Language import Database.Esqueleto.Internal.Sql import Database.Esqueleto.Internal.PersistentImport@@ -439,3 +441,27 @@              , PersistEntity val )           => Key val -> ReaderT backend m () deleteKey = Database.Persist.delete++-- | Avoid N+1 queries and join entities into a map structure+-- @+-- getFoosAndNestedBarsFromParent :: ParentId -> (Map (Key Foo) (Foo, [Maybe (Entity Bar)]))+-- getFoosAndNestedBarsFromParent parentId = 'fmap' associateJoin $ 'select' $+-- 'from' $ \\(foo `'LeftOuterJoin`` bar) -> do+--   'on' (bar '?.' BarFooId '==.' foo '^.' FooId)+--   'where_' (foo '^.' FooParentId '==.' 'val' parentId)+--   'pure' (foo, bar)+-- @+-- /Since: 3.1.2/+associateJoin+  :: forall e1 e0+   . Ord (Key e0)+  => [(Entity e0, e1)]+  -> Map.Map (Key e0) (e0, [e1])+associateJoin = foldr f start+  where+    start = Map.empty+    f (one, many) =+      Map.insertWith+        (\(oneOld, manyOld) (_, manyNew) -> (oneOld, manyNew ++ manyOld ))+        (entityKey one)+        (entityVal one, [many])