From 146121c025fdabc58599c58e24c48ac7e236ee0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Le=20Dorze?= Date: Thu, 8 Jun 2017 14:05:06 +0200 Subject: [PATCH 1/3] Create README.md Highlight the correspondance of pg with it's original github repo. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index a215017..0ed7efb 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ purescript-postgresql-client is a PostgreSQL client library for PureScript. To use this library, you need to add `pg` as an npm dependency. +`pg` being the npm repo of https://github.com/brianc/node-postgres + The purspgpp preprocessor has been replaced by [sqltopurs], which is a code generator instead of a preprocessor, and easier to use. 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 2/3] 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 From 13d0fcfb8e436fe8bc7eab0d95dd655ee97a2cb8 Mon Sep 17 00:00:00 2001 From: rightfold Date: Tue, 13 Jun 2017 11:49:07 +0200 Subject: [PATCH 3/3] Formatting --- README.md | 5 ++--- src/Database/PostgreSQL/Value.purs | 14 +++++++------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 0ed7efb..3aa3741 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,8 @@ purescript-postgresql-client is a PostgreSQL client library for PureScript. -To use this library, you need to add `pg` as an npm dependency. - -`pg` being the npm repo of https://github.com/brianc/node-postgres +To use this library, you need to add `pg` as an npm dependency. You can also +find this npm library on [https://github.com/brianc/node-postgres][pg]. The purspgpp preprocessor has been replaced by [sqltopurs], which is a code generator instead of a preprocessor, and easier to use. diff --git a/src/Database/PostgreSQL/Value.purs b/src/Database/PostgreSQL/Value.purs index 673b406..f1cf5df 100644 --- a/src/Database/PostgreSQL/Value.purs +++ b/src/Database/PostgreSQL/Value.purs @@ -3,6 +3,7 @@ module Database.PostgreSQL.Value where import Control.Monad.Eff (kind Effect) import Control.Monad.Error.Class (throwError) import Control.Monad.Except (runExcept) +import Data.Array as Array import Data.Bifunctor (lmap) import Data.ByteString (ByteString) import Data.DateTime.Instant (Instant) @@ -10,7 +11,6 @@ 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 @@ -53,17 +53,17 @@ instance toSQLValueString :: ToSQLValue String where instance fromSQLValueString :: FromSQLValue String where fromSQLValue = lmap show <<< runExcept <<< readString -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 fromSQLValueArray :: (FromSQLValue a) => FromSQLValue (Array a) where + fromSQLValue = traverse fromSQLValue <=< lmap show <<< runExcept <<< readArray instance toSQLValueList :: (ToSQLValue a) => ToSQLValue (List a) where - toSQLValue = toForeign <<< fromFoldable <<< map toSQLValue + toSQLValue = toForeign <<< Array.fromFoldable <<< map toSQLValue + +instance fromSQLValueList :: (FromSQLValue a) => FromSQLValue (List a) where + fromSQLValue = map List.fromFoldable <<< traverse fromSQLValue <=< lmap show <<< runExcept <<< readArray instance toSQLValueByteString :: ToSQLValue ByteString where toSQLValue = toForeign