From 49a2465e5f31e00e87035ed1ea8874bc74bda7ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Le=20Dorze?= Date: Thu, 8 Jun 2017 18:05:58 +0200 Subject: [PATCH] Update Value.purs Add support for toSQLValue for list an array --- src/Database/PostgreSQL/Value.purs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Database/PostgreSQL/Value.purs b/src/Database/PostgreSQL/Value.purs index 471f500..673b406 100644 --- a/src/Database/PostgreSQL/Value.purs +++ b/src/Database/PostgreSQL/Value.purs @@ -10,6 +10,7 @@ import Data.Either (Either) import Data.Foreign (Foreign, isNull, readArray, readBoolean, readChar, readInt, readNumber, readString, toForeign, unsafeFromForeign) import Data.List (List) import Data.List as List +import Data.Array(fromFoldable) import Data.Maybe (Maybe(..)) import Data.Traversable (traverse) import Prelude @@ -55,9 +56,15 @@ instance fromSQLValueString :: FromSQLValue String where instance fromSQLValueArray :: (FromSQLValue a) => FromSQLValue (Array a) where fromSQLValue = traverse fromSQLValue <=< lmap show <<< runExcept <<< readArray +instance toSQLValueArray :: (ToSQLValue a) => ToSQLValue (Array a) where + toSQLValue = toForeign <<< map toSQLValue + instance fromSQLValueList :: (FromSQLValue a) => FromSQLValue (List a) where fromSQLValue = map List.fromFoldable <<< traverse fromSQLValue <=< lmap show <<< runExcept <<< readArray +instance toSQLValueList :: (ToSQLValue a) => ToSQLValue (List a) where + toSQLValue = toForeign <<< fromFoldable <<< map toSQLValue + instance toSQLValueByteString :: ToSQLValue ByteString where toSQLValue = toForeign