Skip to content

Commit 6a39636

Browse files
committed
Define IsSqlValue Maybe instance in terms of Nullable
1 parent a9e9d4c commit 6a39636

2 files changed

Lines changed: 3 additions & 8 deletions

File tree

src/Database/Postgres/SqlValue.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/Database/Postgres/SqlValue.purs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ module Database.Postgres.SqlValue
77
import Prelude
88
import Data.Enum (fromEnum)
99
import Data.Int (toNumber)
10-
import Data.Maybe (Maybe(..))
10+
import Data.Maybe (Maybe)
1111
import Data.Date (year, month, day)
1212
import Data.DateTime (DateTime(DateTime))
1313
import Data.Time (hour, minute, second)
1414
import Unsafe.Coerce (unsafeCoerce)
15+
import Data.Nullable (toNullable)
1516

1617
foreign import data SqlValue :: *
1718

@@ -28,8 +29,7 @@ instance isSqlValueInt :: IsSqlValue Int where
2829
toSql = unsafeCoerce <<< toNumber
2930

3031
instance isSqlValueMaybe :: (IsSqlValue a) => IsSqlValue (Maybe a) where
31-
toSql Nothing = nullSqlValue
32-
toSql (Just x) = toSql x
32+
toSql = unsafeCoerce <<< toNullable <<< (toSql <$> _)
3333

3434
instance isSqlValueDateTime :: IsSqlValue DateTime where
3535
toSql = toSql <<< format
@@ -45,5 +45,3 @@ instance isSqlValueDateTime :: IsSqlValue DateTime where
4545
zeroPad :: Int -> String
4646
zeroPad i | i < 10 = "0" <> (show i)
4747
zeroPad i = show i
48-
49-
foreign import nullSqlValue :: SqlValue

0 commit comments

Comments
 (0)