persistable-types-HDBC-pg-0.0.1.5/0000755000000000000000000000000013133121752014620 5ustar0000000000000000persistable-types-HDBC-pg-0.0.1.5/Setup.hs0000644000000000000000000000005613133121752016255 0ustar0000000000000000import Distribution.Simple main = defaultMain persistable-types-HDBC-pg-0.0.1.5/LICENSE0000644000000000000000000000275613133121752015637 0ustar0000000000000000Copyright (c) 2015, Kei Hibino 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 Kei Hibino 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. persistable-types-HDBC-pg-0.0.1.5/persistable-types-HDBC-pg.cabal0000644000000000000000000000327713133121752022376 0ustar0000000000000000name: persistable-types-HDBC-pg version: 0.0.1.5 synopsis: HDBC and Relational-Record instances of PostgreSQL extended types description: This package contains HDBC Convertible instances and Relational-Record persistable instances of PostgreSQL extended types Supported extended types: inet, cidr homepage: http://khibino.github.io/haskell-relational-record/ license: BSD3 license-file: LICENSE author: Kei Hibino maintainer: ex8k.hibino@gmail.com copyright: Copyright (c) 2015-2017 Kei Hibino category: Database build-type: Simple cabal-version: >=1.10 tested-with: GHC == 8.2.1 , GHC == 8.0.1, GHC == 8.0.2 , GHC == 7.10.1, GHC == 7.10.2, GHC == 7.10.3 , GHC == 7.8.1, GHC == 7.8.2, GHC == 7.8.3, GHC == 7.8.4 , GHC == 7.6.1, GHC == 7.6.2, GHC == 7.6.3 , GHC == 7.4.1, GHC == 7.4.2 extra-source-files: example/inet.sh example/DS.hs example/InetExample.hs library exposed-modules: Database.HDBC.PostgreSQL.Instances Database.HDBC.PostgreSQL.Persistable other-extensions: MultiParamTypeClasses build-depends: base <5 , bytestring , text-postgresql , convertible , HDBC , persistable-record >= 0.4 , relational-query-HDBC hs-source-dirs: src default-language: Haskell2010 persistable-types-HDBC-pg-0.0.1.5/example/0000755000000000000000000000000013133121752016253 5ustar0000000000000000persistable-types-HDBC-pg-0.0.1.5/example/InetExample.hs0000644000000000000000000000037413133121752021026 0ustar0000000000000000{-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE FlexibleInstances #-} module SinglePKey where import DS import Database.HDBC.PostgreSQL.Persistable () $(definePgTable "EXAMPLE" "inet_example" [''Eq, ''Show]) persistable-types-HDBC-pg-0.0.1.5/example/DS.hs0000644000000000000000000000122513133121752017115 0ustar0000000000000000{-# LANGUAGE TemplateHaskell #-} module DS (definePgTable) where import Language.Haskell.TH (Q, Dec, Name) import Database.HDBC.PostgreSQL (connectPostgreSQL) import Database.HDBC.Query.TH (defineTableFromDB) import Database.HDBC.Schema.Driver (Driver (..)) import Database.HDBC.Schema.PostgreSQL (driverPostgreSQL) import Data.PostgreSQL.NetworkAddress addNetAddress :: Driver conn -> Driver conn addNetAddress d = d { typeMap = [ ("inet", [t| Inet |]), ("cidr", [t| Cidr |] ) ] ++ typeMap d } definePgTable :: String -> String -> [Name] -> Q [Dec] definePgTable = defineTableFromDB (connectPostgreSQL "dbname=testdb") (addNetAddress driverPostgreSQL) persistable-types-HDBC-pg-0.0.1.5/example/inet.sh0000755000000000000000000000135313133121752017553 0ustar0000000000000000#!/bin/sh table=EXAMPLE.inet_example create() { cat <), pure, (<*)) import Data.ByteString.Char8 (unpack) import Data.Convertible (Convertible (..), ConvertResult, ConvertError (..)) import Data.PostgreSQL.NetworkAddress (NetAddress (..), Inet (..), Cidr (..)) import Database.HDBC (SqlValue (..)) import Database.HDBC.Record.Persistable () import Database.PostgreSQL.Parser (evalParser) import qualified Database.PostgreSQL.Parser as Parser import Database.PostgreSQL.Printer (execPrinter) import qualified Database.PostgreSQL.Printer as Printer note :: a -> Maybe b -> Either a b note e = maybe (Left e) Right mapConvert :: Show a => String -> String -> a -> Either String b -> ConvertResult b mapConvert srcT destT sv = either (Left . mke) Right where mke em = ConvertError { convSourceValue = show sv , convSourceType = srcT , convDestType = destT , convErrorMessage = em } takeAddressString :: SqlValue -> Maybe String takeAddressString = d where d (SqlString s) = Just s d (SqlByteString s) = Just $ unpack s d _ = Nothing toNetAddress :: SqlValue -> ConvertResult NetAddress toNetAddress qv = mapConvert "SqlValue" "NetAddress" qv $ do s <- note "Fail to take address string from the column value." $ takeAddressString qv evalParser (Parser.netAddress <* Parser.eof) s instance Convertible SqlValue Inet where safeConvert = (Inet <$>) . toNetAddress instance Convertible SqlValue Cidr where safeConvert = (Cidr <$>) . toNetAddress fromNetAddress :: NetAddress -> ConvertResult SqlValue fromNetAddress = pure . SqlString . execPrinter Printer.netAddress instance Convertible Inet SqlValue where safeConvert (Inet n) = fromNetAddress n instance Convertible Cidr SqlValue where safeConvert (Cidr n) = fromNetAddress n