Skip to content

Commit

Permalink
Stub out approach to implementing async libpq
Browse files Browse the repository at this point in the history
  • Loading branch information
lpsmith committed Jul 11, 2013
1 parent e87e001 commit 96c8219
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 1 deletion.
13 changes: 12 additions & 1 deletion postgresql-libpq.cabal
Expand Up @@ -18,11 +18,22 @@ Copyright: (c) 2010 Grant Monroe
(c) 2011 Leon P Smith
Category: Database
Build-type: Custom
-- Extra-source-files:

-- Unfortunately cabal sdist isn't smart enough to catch all hs-source-dirs
-- whether or not they are behind a conditional
Extra-source-files: unix/Database/PostgreSQL/LibPQ/*.hs
windows/Database/PostgreSQL/LibPQ/*.hs

Cabal-version: >=1.8
Library
hs-source-dirs: src
if os(windows)
hs-source-dirs: windows
else
hs-source-dirs: unix

Exposed-modules: Database.PostgreSQL.LibPQ
Database.PostgreSQL.LibPQ.GHC

Build-depends: base >= 4 && < 5
, bytestring
Expand Down
38 changes: 38 additions & 0 deletions unix/Database/PostgreSQL/LibPQ/GHC.hs
@@ -0,0 +1,38 @@
------------------------------------------------------------------------------
-- |
-- Module: Database.PostgreSQL.LibPQ.GHC
-- Copyright: (c) 2013 Leon P Smith
-- License: BSD3
-- Maintainer: Leon P Smith <leon@melding-monads.com>
-- Stability: experimental
--
-- On Unix, this re-implements some of blocking libpq functions in terms of
-- on-blocking libpq operations and GHC's IO manager. This allows
-- these operations to be interrupted by asynchronous exceptions, and means
-- that GHC's runtime is responsible for handling the concurrency instead
-- of the OS kernel.
--
-- This module also re-exports the rest of libpq for convenience's sake.
-- Thus taking advantage of these features should be as simple as importing
-- @LibPQ.GHC@ instead of @LibPQ@.
--
-- On Windows, this just re-exports the vanilla libpq bindings, due to
-- the lack of a satisfactory IO manager on that platform.
--
------------------------------------------------------------------------------

module Database.PostgreSQL.LibPQ.GHC
( module Database.PostgreSQL.LibPQ
, exec
, connectdb
) where

import Database.PostgreSQL.LibPQ hiding (exec, connectdb)
import qualified Data.ByteString as B
import qualified Database.PostgreSQL.LibPQ as LibPQ

exec :: Connection -> B.ByteString -> IO (Maybe Result)
exec = LibPQ.exec

connectdb :: B.ByteString -> IO Connection
connectdb = LibPQ.connectdb
28 changes: 28 additions & 0 deletions windows/Database/PostgreSQL/LibPQ/GHC.hs
@@ -0,0 +1,28 @@
------------------------------------------------------------------------------
-- |
-- Module: Database.PostgreSQL.LibPQ.GHC
-- Copyright: (c) 2013 Leon P Smith
-- License: BSD3
-- Maintainer: Leon P Smith <leon@melding-monads.com>
-- Stability: experimental
--
-- On Unix, this re-implements some of blocking libpq functions in terms of
-- on-blocking libpq operations and GHC's IO manager. This allows
-- these operations to be interrupted by asynchronous exceptions, and means
-- that GHC's runtime is responsible for handling the concurrency instead
-- of the OS kernel.
--
-- This module also re-exports the rest of libpq for convenience's sake.
-- Thus taking advantage of these features should be as simple as importing
-- @LibPQ.GHC@ instead of @LibPQ@.
--
-- On Windows, this just re-exports the vanilla libpq bindings, due to
-- the lack of a satisfactory IO manager on that platform.
--
------------------------------------------------------------------------------

module Database.PostgreSQL.LibPQ.GHC
( module Database.PostgreSQL.LibPQ
) where

import Database.PostgreSQL.LibPQ

0 comments on commit 96c8219

Please sign in to comment.