packages feed

beam-postgres 0.6.1.0 → 0.6.2.0

raw patch · 12 files changed

+81/−60 lines, 12 filesdep ~hedgehogPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: hedgehog

API changes (from Hackage documentation)

+ Database.Beam.Postgres.Extensions: PgHasExtension :: Text -> PgHasExtension
+ Database.Beam.Postgres.Extensions: class IsPgExtension extension
+ Database.Beam.Postgres.Extensions: data PgExtensionEntity extension
+ Database.Beam.Postgres.Extensions: funcE :: IsSql99ExpressionSyntax expr => Text -> [expr] -> expr
+ Database.Beam.Postgres.Extensions: getPgExtension :: forall (db :: (Type -> Type) -> Type) extension. DatabaseEntity Postgres db (PgExtensionEntity extension) -> extension
+ Database.Beam.Postgres.Extensions: instance Data.Hashable.Class.Hashable Database.Beam.Postgres.Extensions.PgHasExtension
+ Database.Beam.Postgres.Extensions: instance Database.Beam.Migrate.Types.CheckedEntities.IsCheckedDatabaseEntity Database.Beam.Postgres.Types.Postgres (Database.Beam.Postgres.Extensions.PgExtensionEntity extension)
+ Database.Beam.Postgres.Extensions: instance Database.Beam.Migrate.Types.Predicates.DatabasePredicate Database.Beam.Postgres.Extensions.PgHasExtension
+ Database.Beam.Postgres.Extensions: instance Database.Beam.Schema.Tables.IsDatabaseEntity Database.Beam.Postgres.Types.Postgres (Database.Beam.Postgres.Extensions.PgExtensionEntity extension)
+ Database.Beam.Postgres.Extensions: instance Database.Beam.Schema.Tables.RenamableWithRule (Database.Beam.Schema.Tables.FieldRenamer (Database.Beam.Schema.Tables.DatabaseEntityDescriptor Database.Beam.Postgres.Types.Postgres (Database.Beam.Postgres.Extensions.PgExtensionEntity e)))
+ Database.Beam.Postgres.Extensions: instance GHC.Classes.Eq Database.Beam.Postgres.Extensions.PgHasExtension
+ Database.Beam.Postgres.Extensions: instance GHC.Internal.Generics.Generic Database.Beam.Postgres.Extensions.PgHasExtension
+ Database.Beam.Postgres.Extensions: instance GHC.Internal.Show.Show Database.Beam.Postgres.Extensions.PgHasExtension
+ Database.Beam.Postgres.Extensions: newtype PgHasExtension
+ Database.Beam.Postgres.Extensions: pgCreateExtension :: forall extension (db :: (Type -> Type) -> Type). IsPgExtension extension => Migration Postgres (CheckedDatabaseEntity Postgres db (PgExtensionEntity extension))
+ Database.Beam.Postgres.Extensions: pgDropExtension :: CheckedDatabaseEntityDescriptor Postgres (PgExtensionEntity extension) -> Migration Postgres ()
+ Database.Beam.Postgres.Extensions: pgExtensionActionProvider :: ActionProvider Postgres
+ Database.Beam.Postgres.Extensions: pgExtensionBuild :: IsPgExtension extension => extension
+ Database.Beam.Postgres.Extensions: pgExtensionName :: IsPgExtension extension => Proxy extension -> Text
+ Database.Beam.Postgres.Extensions: type PgExpr ctxt s = QGenExpr ctxt Postgres s
+ Database.Beam.Postgres.Extensions: type family LiftPg ctxt s fn

Files

ChangeLog.md view
@@ -1,3 +1,18 @@+# 0.6.2.0++## Added features++* Added instances for `BeamSqlBackendIsString Postgres (CI String)` and+  `BeamSqlBackendIsString Postgres (CI Text)`, allowing the use of `toTsVector`+  over colums of type `citext` (#818)+* Exposed the functionality to implement user-defined extensions via+  `Database.Beam.Postgres.Extensions` (#819)++## Bug fixes++* Fixed an issue where using `pgSelectWith` with no common-table expressions+  would lead to an invalid SQL query at runtime.+ # 0.6.1.0  ## Added features@@ -17,7 +32,7 @@   role attribute and is the appropriate choice when the client and   server are on different hosts — see   `Database.Beam.Postgres.Extensions.Copy.Stream`.-  + ## Bug fixes  * Fixed an issue where a window function applied over the result of `nub_` (or
Database/Beam/Postgres/Connection.hs view
@@ -9,7 +9,6 @@ {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE OverloadedStrings #-}-{-# LANGUAGE CPP #-} {-# LANGUAGE BangPatterns #-}  module Database.Beam.Postgres.Connection
Database/Beam/Postgres/Extensions.hs view
@@ -1,6 +1,5 @@ {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE UndecidableInstances #-}-{-# LANGUAGE CPP #-}  -- | Postgres extensions are run-time loadable plugins that can extend Postgres -- functionality. Extensions are part of the database schema.@@ -10,9 +9,29 @@ -- the extension in a particular backend. @beam-postgres@ provides predicates -- and checks for @beam-migrate@ which allow extensions to be included as -- regular parts of beam migrations.-module Database.Beam.Postgres.Extensions where+module Database.Beam.Postgres.Extensions (+  -- * Handling extensions+  PgExtensionEntity,+  getPgExtension, +  -- * Defining extensions+  IsPgExtension(..),+  -- ** Helpers+  PgExpr,+  LiftPg,+  funcE,++  -- * Migrations+  PgHasExtension(..),+  pgCreateExtension,+  pgDropExtension,+  pgExtensionActionProvider,+) where+ import           Database.Beam+import           Database.Beam.Backend.SQL ( IsSql92ExpressionSyntax(..), IsSql92FieldNameSyntax(..),+                                             IsSql99ExpressionSyntax, IsSql99FunctionExpressionSyntax(..)+                                           ) import           Database.Beam.Schema.Tables  import           Database.Beam.Postgres.Types@@ -122,6 +141,21 @@                -> extension getPgExtension (DatabaseEntity (PgDatabaseExtension _ ext)) = ext +-- *** Helpers to write postgres user-defined extensions++-- | @since 0.6.2.0+type PgExpr ctxt s = QGenExpr ctxt Postgres s++-- | @since 0.6.2.0+type family LiftPg ctxt s fn where+  LiftPg ctxt s (Maybe a -> b) = Maybe (PgExpr ctxt s a) -> LiftPg ctxt s b+  LiftPg ctxt s (a -> b) = PgExpr ctxt s a -> LiftPg ctxt s b+  LiftPg ctxt s a = PgExpr ctxt s a++-- | @since 0.6.2.0+funcE :: IsSql99ExpressionSyntax expr => Text -> [expr] -> expr+funcE nm = functionCallE (fieldE (unqualifiedField nm))+ -- *** Migrations support for extensions  -- | 'Migration' representing the Postgres @CREATE EXTENSION@ command. Because@@ -192,3 +226,4 @@      pure (PotentialAction (HS.fromList [p extP]) mempty                            (pure (MigrationCommand cmd MigrationKeepsData))                            ("Unload the postgres extension " <> ext) 1)+
− Database/Beam/Postgres/Extensions/Internal.hs
@@ -1,17 +0,0 @@-module Database.Beam.Postgres.Extensions.Internal where--import Data.Text (Text)--import Database.Beam-import Database.Beam.Backend.SQL-import Database.Beam.Postgres--type PgExpr ctxt s = QGenExpr ctxt Postgres s--type family LiftPg ctxt s fn where-  LiftPg ctxt s (Maybe a -> b) = Maybe (PgExpr ctxt s a) -> LiftPg ctxt s b-  LiftPg ctxt s (a -> b) = PgExpr ctxt s a -> LiftPg ctxt s b-  LiftPg ctxt s a = PgExpr ctxt s a--funcE :: IsSql99ExpressionSyntax expr => Text -> [expr] -> expr-funcE nm args = functionCallE (fieldE (unqualifiedField nm)) args
Database/Beam/Postgres/Extensions/UuidOssp.hs view
@@ -10,8 +10,7 @@ import           Data.UUID.Types (UUID)  import           Database.Beam-import           Database.Beam.Postgres.Extensions-import           Database.Beam.Postgres.Extensions.Internal+import           Database.Beam.Postgres.Extensions ( LiftPg, IsPgExtension(..), funcE )  -- | Data type representing definitions contained in the @uuid-ossp@ extension data UuidOssp = UuidOssp
Database/Beam/Postgres/Full.hs view
@@ -2,7 +2,6 @@ {-# LANGUAGE UndecidableInstances #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE TupleSections #-}-{-# LANGUAGE CPP #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE TypeOperators #-} @@ -71,6 +70,8 @@ import           Control.Monad.State.Strict (evalState) import           Control.Monad.Writer (runWriterT) +import           Data.List.NonEmpty (nonEmpty)+import qualified Data.List.NonEmpty as NonEmpty import           Data.Kind (Type) import           Data.Proxy (Proxy(..)) import qualified Data.Text as T@@ -289,18 +290,21 @@ -- -- @beam-core@ offers 'selectWith' to produce a top-level 'SqlSelect' -- but these cannot be turned into 'Q' objects for use within joins.------ The 'pgSelectWith' function is more flexible and indeed--- 'selectWith' for @beam-postgres@ is equivalent to se+-- The 'pgSelectWith' function is more flexible. pgSelectWith :: forall db s res               . Projectible Postgres res              => With Postgres db (Q Postgres db s res) -> Q Postgres db s res pgSelectWith (CTE.With mkQ) =-    let (q, (recursiveness, ctes)) = evalState (runWriterT mkQ) 0+    let (q, (recursiveness, mctes)) = evalState (runWriterT mkQ) 0         fromSyntax tblPfx =-            case recursiveness of-              CTE.Nonrecursive -> withSyntax ctes (buildSqlQuery tblPfx q)-              CTE.Recursive -> withRecursiveSyntax ctes (buildSqlQuery tblPfx q)+            case (recursiveness, nonEmpty mctes) of+              (CTE.Nonrecursive, Just ctes) -> withSyntax (NonEmpty.toList ctes) (buildSqlQuery tblPfx q)+              (CTE.Recursive, Just ctes) -> withRecursiveSyntax (NonEmpty.toList ctes) (buildSqlQuery tblPfx q)+               -- If there are no subqueries, we don't want to generate+               -- an empty 'WITH' statement, which would be malformed.+               -- +               -- see: https://github.com/haskell-beam/beam/issues/760+              (_, Nothing) -> buildSqlQuery tblPfx q     in Q (liftF (QAll (\tblPfx tName ->                            let (_, names) = mkFieldNames @Postgres @res (qualifiedField tName)                            in fromTable (PgTableSourceSyntax $@@ -309,7 +313,7 @@                       (\tName ->                            let (projection, _) = mkFieldNames @Postgres @res (qualifiedField tName)                            in projection)-                      (\_ -> Nothing)+                      (const Nothing)                       snd))  -- | By default, Postgres will throw an error when a conflict is detected. This
Database/Beam/Postgres/Migrate.hs view
@@ -60,7 +60,7 @@ import           Control.Exception.Lifted (mask, onException) import           Control.Monad -import           Data.Aeson hiding (json)+import           Data.Aeson import           Data.Bits import           Data.ByteString (ByteString) import qualified Data.ByteString.Lazy as BL
Database/Beam/Postgres/PgCrypto.hs view
@@ -9,8 +9,7 @@ import Database.Beam import Database.Beam.Backend.SQL -import Database.Beam.Postgres.Extensions-import Database.Beam.Postgres.Extensions.Internal+import Database.Beam.Postgres.Extensions( LiftPg, PgExpr, IsPgExtension(..), funcE )  import Data.Int import Data.Text (Text)
Database/Beam/Postgres/PgSpecific.hs view
@@ -9,7 +9,6 @@ {-# LANGUAGE TypeApplications #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE PolyKinds #-}-{-# LANGUAGE CPP #-}  -- | Postgres-specific types, functions, and operators module Database.Beam.Postgres.PgSpecific
Database/Beam/Postgres/Types.hs view
@@ -1,5 +1,5 @@ {-# OPTIONS_GHC -fno-warn-orphans #-}-+{-# LANGUAGE CPP #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE UndecidableInstances #-} {-# LANGUAGE MultiParamTypeClasses #-}@@ -184,6 +184,12 @@  instance BeamSqlBackendIsString Postgres String instance BeamSqlBackendIsString Postgres Text++-- | @since 0.6.2.0+instance BeamSqlBackendIsString Postgres (CI String)++-- | @since 0.6.2.0+instance BeamSqlBackendIsString Postgres (CI Text)  instance HasQBuilder Postgres where   buildSqlQuery = buildSql92Query' True
beam-postgres.cabal view
@@ -1,5 +1,5 @@ name:                 beam-postgres-version:              0.6.1.0+version:              0.6.2.0 synopsis:             Connection layer between beam and postgres description:          Beam driver for <https://www.postgresql.org/ PostgreSQL>, an advanced open-source RDBMS homepage:             https://haskell-beam.github.io/beam/user-guide/backends/beam-postgres@@ -23,16 +23,15 @@                       Database.Beam.Postgres.Full                        Database.Beam.Postgres.PgCrypto+                      Database.Beam.Postgres.Extensions                       Database.Beam.Postgres.Extensions.UuidOssp                        Database.Beam.Postgres.TempTable    other-modules:      Database.Beam.Postgres.Connection                       Database.Beam.Postgres.Debug-                      Database.Beam.Postgres.Extensions                       Database.Beam.Postgres.Extensions.Copy.File                       Database.Beam.Postgres.Extensions.Copy.Stream-                      Database.Beam.Postgres.Extensions.Internal                       Database.Beam.Postgres.PgSpecific                       Database.Beam.Postgres.Types @@ -54,7 +53,7 @@                       monad-control        >=1.0  && <1.1,                       mtl                  >=2.1  && <2.4,                       conduit              >=1.2  && <1.4,-                      aeson                >=0.11 && <2.3,+                      aeson                >=0.11 && <2.4,                       uuid-types           >=1.0  && <1.1,                       case-insensitive     >=1.2  && <1.3,                       scientific           >=0.3  && <0.4,@@ -67,7 +66,7 @@   default-language:   Haskell2010   default-extensions: ScopedTypeVariables, OverloadedStrings, MultiParamTypeClasses, RankNTypes, FlexibleInstances,                       DeriveDataTypeable, DeriveGeneric, StandaloneDeriving, TypeFamilies, GADTs, OverloadedStrings,-                      CPP, TypeApplications, FlexibleContexts+                      TypeApplications, FlexibleContexts   ghc-options:        -Wall                       -Widentities                       -Wincomplete-uni-patterns@@ -97,7 +96,7 @@     beam-migrate,     beam-postgres,     bytestring,-    hedgehog,+    hedgehog >= 1.0,     postgresql-simple,     tasty-hunit,     tasty,
test/Database/Beam/Postgres/Test.hs view
@@ -1,10 +1,5 @@-{-# LANGUAGE CPP #-} module Database.Beam.Postgres.Test where -#if MIN_VERSION_base(4,12,0)-import           Prelude hiding (fail)-#endif- import qualified Database.PostgreSQL.Simple as Pg  import           Control.Exception (bracket)@@ -13,18 +8,6 @@  import           Data.ByteString (ByteString) import           Data.String--#if MIN_VERSION_base(4,12,0)-#if !MIN_VERSION_hedgehog(1,0,0)-import           Control.Monad.Fail (MonadFail(..))-import qualified Hedgehog--- TODO orphan instances are bad--- Would be easier to say 'build-depends: hedgehog >= 1.0',--- but it's difficult to propagate to older Stackage snapshots-instance Monad m => MonadFail (Hedgehog.PropertyT m) where-    fail _ = Hedgehog.failure-#endif-#endif  withTestPostgres :: String -> IO ByteString -> (Pg.Connection -> IO a) -> IO a withTestPostgres dbName getConnStr action = do