Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion beam-postgres/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* 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

Expand All @@ -30,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
Expand Down
38 changes: 37 additions & 1 deletion beam-postgres/Database/Beam/Postgres/Extensions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,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
Expand Down Expand Up @@ -121,6 +141,21 @@ getPgExtension :: DatabaseEntity Postgres db (PgExtensionEntity extension)
-> 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
Expand Down Expand Up @@ -191,3 +226,4 @@ pgDropExtensionProvider =
pure (PotentialAction (HS.fromList [p extP]) mempty
(pure (MigrationCommand cmd MigrationKeepsData))
("Unload the postgres extension " <> ext) 1)

17 changes: 0 additions & 17 deletions beam-postgres/Database/Beam/Postgres/Extensions/Internal.hs

This file was deleted.

3 changes: 1 addition & 2 deletions beam-postgres/Database/Beam/Postgres/Extensions/UuidOssp.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import Data.Text (Text)
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
Expand Down
3 changes: 1 addition & 2 deletions beam-postgres/Database/Beam/Postgres/PgCrypto.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ module Database.Beam.Postgres.PgCrypto
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)
Expand Down
3 changes: 1 addition & 2 deletions beam-postgres/beam-postgres.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,15 @@ library
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

Expand Down
Loading