From 4eb4a8972b636d2aece72b75692225f10bdc0db6 Mon Sep 17 00:00:00 2001 From: Shane O'Brien Date: Wed, 18 Sep 2024 12:41:11 +0100 Subject: [PATCH] Expose unsafeUnnullify and unsafeUnnullifyTable --- changelog.d/20240918_124205_shane.obrien.md | 3 +++ src/Rel8.hs | 2 ++ src/Rel8/Expr/Null.hs | 4 ++++ src/Rel8/Table/Null.hs | 1 + 4 files changed, 10 insertions(+) create mode 100644 changelog.d/20240918_124205_shane.obrien.md diff --git a/changelog.d/20240918_124205_shane.obrien.md b/changelog.d/20240918_124205_shane.obrien.md new file mode 100644 index 00000000..197c1266 --- /dev/null +++ b/changelog.d/20240918_124205_shane.obrien.md @@ -0,0 +1,3 @@ +### Added + +- Expose `unsafeUnnullify` and `unsafeUnnullifyTable` from `Rel8`. diff --git a/src/Rel8.hs b/src/Rel8.hs index 0d7f87d0..dc612730 100644 --- a/src/Rel8.hs +++ b/src/Rel8.hs @@ -129,6 +129,7 @@ module Rel8 , catNullTable , nameNullTable , toNullTable, toMaybeTable + , unsafeUnnullifyTable -- ** Algebraic data types / sum types -- $adts @@ -184,6 +185,7 @@ module Rel8 , liftOpNull , catNull , coalesce + , unsafeUnnullify -- ** Boolean operations , DBEq diff --git a/src/Rel8/Expr/Null.hs b/src/Rel8/Expr/Null.hs index 1f1430fd..9d3987f9 100644 --- a/src/Rel8/Expr/Null.hs +++ b/src/Rel8/Expr/Null.hs @@ -35,6 +35,10 @@ nullify :: NotNull a => Expr a -> Expr (Maybe a) nullify (Expr a) = Expr a +-- | Assume that a nullable column's value is non-null. If the column is +-- actually @null@, this will lead to runtime errors when you try to decode +-- the value into Haskell, so you should prefer to use 'Rel8.nullable' +-- unless you know what you're doing. unsafeUnnullify :: Expr (Maybe a) -> Expr a unsafeUnnullify (Expr a) = Expr a diff --git a/src/Rel8/Table/Null.hs b/src/Rel8/Table/Null.hs index 0e9e68c5..754dde23 100644 --- a/src/Rel8/Table/Null.hs +++ b/src/Rel8/Table/Null.hs @@ -126,6 +126,7 @@ nullifyTable :: a -> NullTable Expr a nullifyTable = NullTable . pure +-- | Assume that a 'NullTable' is non-null. Like 'Rel8.unsafeUnnullify'. unsafeUnnullifyTable :: NullTable Expr a -> a unsafeUnnullifyTable (NullTable a) = extract a