postgresql-typed-lifted (empty) → 0.5.1.1
raw patch · 8 files changed
+372/−0 lines, 8 filesdep +basedep +base-unicode-symbolsdep +bytestringsetup-changed
Dependencies added: base, base-unicode-symbols, bytestring, exceptions, lens, monad-control, postgresql-typed, transformers-base
Files
- CODE_OF_CONDUCT.md +74/−0
- LICENSE +30/−0
- README.md +14/−0
- Setup.hs +2/−0
- Source/Library/Database/PostgreSQL/Typed/Lifted.hs +15/−0
- Source/Library/Database/PostgreSQL/Typed/Lifted/Protocol.hs +160/−0
- Source/Library/Database/PostgreSQL/Typed/Lifted/Query.hs +34/−0
- postgresql-typed-lifted.cabal +43/−0
+ CODE_OF_CONDUCT.md view
@@ -0,0 +1,74 @@+# Contributor Covenant Code of Conduct++## Our Pledge++In the interest of fostering an open and welcoming environment, we as+contributors and maintainers pledge to making participation in our project and+our community a harassment-free experience for everyone, regardless of age, body+size, disability, ethnicity, gender identity and expression, level of experience,+nationality, personal appearance, race, religion, or sexual identity and+orientation.++## Our Standards++Examples of behavior that contributes to creating a positive environment+include:++* Using welcoming and inclusive language+* Being respectful of differing viewpoints and experiences+* Gracefully accepting constructive criticism+* Focusing on what is best for the community+* Showing empathy towards other community members++Examples of unacceptable behavior by participants include:++* The use of sexualized language or imagery and unwelcome sexual attention or+advances+* Trolling, insulting/derogatory comments, and personal or political attacks+* Public or private harassment+* Publishing others' private information, such as a physical or electronic+ address, without explicit permission+* Other conduct which could reasonably be considered inappropriate in a+ professional setting++## Our Responsibilities++Project maintainers are responsible for clarifying the standards of acceptable+behavior and are expected to take appropriate and fair corrective action in+response to any instances of unacceptable behavior.++Project maintainers have the right and responsibility to remove, edit, or+reject comments, commits, code, wiki edits, issues, and other contributions+that are not aligned to this Code of Conduct, or to ban temporarily or+permanently any contributor for other behaviors that they deem inappropriate,+threatening, offensive, or harmful.++## Scope++This Code of Conduct applies both within project spaces and in public spaces+when an individual is representing the project or its community. Examples of+representing a project or community include using an official project e-mail+address, posting via an official social media account, or acting as an appointed+representative at an online or offline event. Representation of a project may be+further defined and clarified by project maintainers.++## Enforcement++Instances of abusive, harassing, or otherwise unacceptable behavior may be+reported by contacting the project team at [INSERT EMAIL ADDRESS]. All+complaints will be reviewed and investigated and will result in a response that+is deemed necessary and appropriate to the circumstances. The project team is+obligated to maintain confidentiality with regard to the reporter of an incident.+Further details of specific enforcement policies may be posted separately.++Project maintainers who do not follow or enforce the Code of Conduct in good+faith may face temporary or permanent repercussions as determined by other+members of the project's leadership.++## Attribution++This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,+available at [http://contributor-covenant.org/version/1/4][version]++[homepage]: http://contributor-covenant.org+[version]: http://contributor-covenant.org/version/1/4/
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2017, Evan Cofsky++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of Evan Cofsky nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README.md view
@@ -0,0 +1,14 @@+# PostgreSQL Typed: Lifted++This provides lifted operations+from+[PostgreSQL Typed](http://hackage.haskell.org/package/postgresql-typed). The+operations are lifted+into+[MonadBaseControl](https://hackage.haskell.org/package/monad-control),+and exceptions are lifted+with [Exceptions](https://hackage.haskell.org/package/exceptions).++## Versioning++The version numbers we use track [PostgreSQL Typed](http://hackage.haskell.org/package/postgresql-typed).
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ Source/Library/Database/PostgreSQL/Typed/Lifted.hs view
@@ -0,0 +1,15 @@+{-|+Module: Database.PostgreSQL.Typed.Lifted+Description: Lifted versions of PostgreSQL Typed.+Copyright: © 2017 All rights reserved.+License: BSD3+Maintainer: Evan Cofsky <evan@theunixman.com>+Stability: experimental+Portability: POSIX+-}++module Database.PostgreSQL.Typed.Lifted (+ module Database.PostgreSQL.Typed.Lifted.Protocol+ ) where++import Database.PostgreSQL.Typed.Lifted.Protocol
+ Source/Library/Database/PostgreSQL/Typed/Lifted/Protocol.hs view
@@ -0,0 +1,160 @@+{-|+Module: Database.PostgreSQL.Typed.Lifted.Protocol+Description: Protocol package.+Copyright: © 2017 All rights reserved.+License: BSD3+Maintainer: Evan Cofsky <evan@theunixman.com>+Stability: experimental+Portability: POSIX+-}++module Database.PostgreSQL.Typed.Lifted.Protocol (+ module Database.PostgreSQL.Typed,+ module Database.PostgreSQL.Typed.Protocol,+ module Database.PostgreSQL.Typed.Types,+ RawStatement,+ ChunkRows,+ pgConnect,+ pgDisconnect,+ pgReconnect,++ pgDescribe,+ pgSimpleQuery,+ pgSimpleQueries_,+ pgPreparedQuery,+ pgPreparedLazyQuery,+ pgCloseStatement,++ pgBegin,+ pgCommit,+ pgRollback,+ pgCommitAll,+ pgRollbackAll,+ pgTransaction+ ) where++import Prelude.Unicode+import Data.String (IsString(..))+import Data.Word+import Control.Lens+import Control.Monad.Base+import Control.Monad.Trans.Control+import Control.Monad.Catch+import qualified Data.ByteString.Lazy as BSL+import qualified Data.ByteString as BS++import Database.PostgreSQL.Typed.Types++import Database.PostgreSQL.Typed (+ pgSQL,+ PGDatabase(..),+ defaultPGDatabase)+import Database.PostgreSQL.Typed.Protocol (PGConnection)+import qualified Database.PostgreSQL.Typed.Protocol as P+++-- * Connection management++pgConnect ∷ (MonadBaseControl IO m) ⇒ PGDatabase -> m PGConnection+pgConnect = liftBase ∘ P.pgConnect++pgDisconnect ∷ (MonadBaseControl IO m) ⇒ PGConnection -> m ()+pgDisconnect = liftBase ∘ P.pgDisconnect++pgReconnect ∷ (MonadBaseControl IO m) ⇒ PGConnection → PGDatabase → m PGConnection+pgReconnect conn = liftBase ∘ P.pgReconnect conn++-- * Simple Queries that are just raw SQL++-- | Wrapper for raw SQL statements.+newtype RawStatement = RawStatement {unRawStatement ∷ BSL.ByteString}+ deriving (Eq, Ord, Show, Monoid, IsString)++raw ∷ Iso' RawStatement BSL.ByteString+raw = iso unRawStatement RawStatement++strictRaw ∷ Iso' RawStatement BS.ByteString+strictRaw = iso (BSL.toStrict ∘ unRawStatement) (RawStatement ∘ BSL.fromStrict)++-- ** Operations on a PGConnection++pgDescribe ∷ (MonadBaseControl IO m, Traversable f) ⇒+ PGConnection+ → RawStatement -- ^ SQL string+ → f OID -- ^ Optional type specifications+ → Bool -- ^ Guess nullability, otherwise assume everything is+ → m ([OID], [(BS.ByteString, OID, Bool)])+ -- ^ a list of parameter types, and a list of result+ -- field names, types, and nullability indicators.+pgDescribe c s types nulls = liftBase $ P.pgDescribe c (s ^. raw) (toListOf traversed types) nulls++pgSimpleQuery ∷ (MonadBaseControl IO m) ⇒+ PGConnection+ → RawStatement+ → m (Int, [PGValues])+pgSimpleQuery c s = liftBase $ P.pgSimpleQuery c (s ^. raw)++pgSimpleQueries_ ∷ (MonadBaseControl IO m) ⇒+ PGConnection+ → RawStatement+ → m ()+pgSimpleQueries_ c s = liftBase $ P.pgSimpleQueries_ c (s ^. raw)++pgPreparedQuery ∷ (MonadBaseControl IO m, Traversable f) ⇒+ PGConnection+ → RawStatement+ → f OID+ → PGValues+ → f Bool+ → m (Int, [PGValues])+pgPreparedQuery c s oids vals bins =+ liftBase+ $ P.pgPreparedQuery c (s ^. strictRaw) (toListOf traversed oids) vals (toListOf traversed bins)++newtype ChunkRows = ChunkRows {unChunkRows ∷ Word32}+ deriving (Eq, Ord, Show, Bounded, Enum, Real, Integral, Num)++chunkRows ∷ Iso' ChunkRows Word32+chunkRows = iso unChunkRows ChunkRows++pgPreparedLazyQuery ∷ (MonadBaseControl IO m, Traversable f) ⇒+ PGConnection+ → RawStatement+ → f OID+ → PGValues+ → f Bool+ → ChunkRows+ → m ([PGValues])+pgPreparedLazyQuery c s oids vals bins chunk =+ liftBase+ $ P.pgPreparedLazyQuery c (s ^. strictRaw) (toListOf traversed oids)+ vals (toListOf traversed bins) (chunk ^. chunkRows)++pgCloseStatement ∷ (MonadBaseControl IO m, Traversable f) ⇒+ PGConnection → RawStatement → f OID → m ()+pgCloseStatement c s oids =+ liftBase $ P.pgCloseStatement c (s ^. strictRaw) (toListOf traversed oids)++-- * Transactions++pgBegin ∷ (MonadBaseControl IO m) ⇒ PGConnection → m ()+pgBegin = liftBase ∘ P.pgBegin++pgCommit ∷ (MonadBaseControl IO m) ⇒ PGConnection → m ()+pgCommit = liftBase ∘ P.pgCommit++pgRollback ∷ (MonadBaseControl IO m) ⇒ PGConnection → m ()+pgRollback = liftBase ∘ P.pgRollback++pgCommitAll ∷ (MonadBaseControl IO m) ⇒ PGConnection → m ()+pgCommitAll = liftBase ∘ P.pgCommitAll++pgRollbackAll ∷ (MonadBaseControl IO m) ⇒ PGConnection → m ()+pgRollbackAll = liftBase ∘ P.pgRollbackAll++pgTransaction ∷ (MonadCatch m, MonadBaseControl IO m) ⇒ PGConnection → m a → m a+pgTransaction conn f = do+ pgBegin conn+ a ← onException f (pgRollback conn)+ pgCommit conn+ return a
+ Source/Library/Database/PostgreSQL/Typed/Lifted/Query.hs view
@@ -0,0 +1,34 @@+{-|+Module: Database.PostgreSQL.Typed.Lifted.Query+Description: Lifted versions of Database.PostgreSQL.Typed.Query+Copyright: © 2017 All rights reserved.+License: BSD3+Maintainer: Evan Cofsky <evan@theunixman.com>+Stability: experimental+Portability: POSIX+-}++module Database.PostgreSQL.Typed.Lifted.Query (+ module Database.PostgreSQL.Typed.Query,+ pgExecute,+ pgQuery,+ pgLazyQuery+ ) where++import Control.Monad.Base+import Control.Monad.Trans.Control+import Database.PostgreSQL.Typed.Query hiding (pgExecute, pgQuery, pgLazyQuery)+import Database.PostgreSQL.Typed.Lifted.Protocol+import qualified Database.PostgreSQL.Typed.Query as Q++pgExecute ∷ (MonadBaseControl IO m, PGQuery q ()) ⇒+ PGConnection → q → m Int+pgExecute c q = liftBase $ Q.pgExecute c q++pgQuery ∷ (MonadBaseControl IO m, PGQuery q a) ⇒+ PGConnection → q → m [a]+pgQuery c q = liftBase $ Q.pgQuery c q++pgLazyQuery ∷ (MonadBaseControl IO m) ⇒+ PGConnection → PGPreparedQuery a → ChunkRows → m [a]+pgLazyQuery c q r = liftBase $ Q.pgLazyQuery c q (fromIntegral r)
+ postgresql-typed-lifted.cabal view
@@ -0,0 +1,43 @@+-- Initial postgresql-typed-lifted.cabal generated by cabal init. For+-- further documentation, see http://haskell.org/cabal/users-guide/++name: postgresql-typed-lifted+version: 0.5.1.1+synopsis: postgresql-typed operations lifted to any instance of MonadBase or MonadBaseControl.+description: Provides generalized lifted operations for postgresql-typed. Version numbers track postgresql-typed.+homepage: https://gitlab.com/theunixman/postgresql-typed-lifted+license: BSD3+license-file: LICENSE+author: Evan Cofsky+maintainer: evan@theunixman.com+copyright: 2017 Evan Cofsky+category: Database+build-type: Simple+extra-source-files:+ README.md+ CODE_OF_CONDUCT.md+cabal-version: >=1.10++library+ ghc-options: -Wall -Wno-redundant-constraints -Wno-type-defaults -O2+ exposed-modules:+ Database.PostgreSQL.Typed.Lifted+ Database.PostgreSQL.Typed.Lifted.Protocol+ Database.PostgreSQL.Typed.Lifted.Query+ build-depends:+ base >=4.8 && <5,+ base-unicode-symbols >= 0.2.2.4 && < 0.3,+ bytestring >= 0.10.2 && < 0.11,+ exceptions >= 0.8.3 && < 0.9,+ lens >= 4.14 && < 4.18,+ monad-control >= 0.3 && < 1.1,+ transformers-base >= 0.4 && < 0.5,+ postgresql-typed >= 0.5.1 && < 0.6+ hs-source-dirs:+ Source/Library+ default-language:+ Haskell2010+ default-extensions:+ FlexibleContexts+ GeneralizedNewtypeDeriving+ UnicodeSyntax