From 9fd81b56a866693b0808fdc6218de8fdfdc4436e Mon Sep 17 00:00:00 2001 From: parsonsmatt Date: Mon, 13 Jan 2025 10:56:53 -0700 Subject: [PATCH] no sqlcoerce yet --- changelog.md | 3 ++ src/Database/Esqueleto/Internal/Internal.hs | 48 --------------------- 2 files changed, 3 insertions(+), 48 deletions(-) diff --git a/changelog.md b/changelog.md index 748012e3d..2049c6c60 100644 --- a/changelog.md +++ b/changelog.md @@ -64,6 +64,9 @@ - The ability to `coerce` `SqlExpr` was removed. Instead, use `veryUnsafeCoerceSqlExpr`. See the documentation on `veryUnsafeCoerceSqlExpr` for safe use example. + - `unsafeCeorceSqlExpr` is provided as an option when the underlying + Haskell types are coercible. This is still unsafe, as different + `PersistFieldSql` instances may be at play. - [#420](https://github.com/bitemyapp/esqueleto/pull/421) - The `LockingKind` constructors are deprecated, and will be removed from non-Internal modules in a future release. Smart constructors diff --git a/src/Database/Esqueleto/Internal/Internal.hs b/src/Database/Esqueleto/Internal/Internal.hs index a70ca7f5f..9541c90b7 100644 --- a/src/Database/Esqueleto/Internal/Internal.hs +++ b/src/Database/Esqueleto/Internal/Internal.hs @@ -2523,54 +2523,6 @@ veryUnsafeCoerceSqlExpr (ERaw m k) = ERaw m k unsafeCoerceSqlExpr :: (Coercible a b) => SqlExpr a -> SqlExpr b unsafeCoerceSqlExpr = veryUnsafeCoerceSqlExpr --- | This type class provides a relation between two types @arg@ and @result@ --- such that @arg@ can be coerced into @result@ safely. --- --- For this to be generally true, you should ensure that the 'sqlType' method --- agrees for each type. See 'testSqlCoerce' for a function which does this. --- --- You will likely want to write bidirectional instances. That is, for two types --- @A@ and @B@, you'll likely want to write: --- --- @ --- instance SqlCoerce A B --- --- instance SqlCoerce B A --- @ --- --- That way, you can coerce along either way. --- --- @since 3.6.0.0 -class SqlCoerce arg result where - -- | A Haskell value-level witness that you can safely - -- - -- @since 3.6.0.0 - sqlCoerceWitness :: arg -> result - - -- | Included as a class member to make importing the function easier. - -- However, this is defaulted to 'veryUnsafeCoerceSqlExpr', so you - -- probably don't want to define your own implementations. - sqlCoerce :: SqlExpr arg -> SqlExpr result - sqlCoerce = veryUnsafeCoerceSqlExpr - --- | This function can be used to test whether or not a 'SqlCoerce' instance is --- safe or not. If the two underlying 'sqlType' are equal, then this returns --- @'Right' ()@. Otherwise, it returns a 'Left' with the two 'TypeRep's, --- allowing you to render failure how you'd like. --- --- @since 3.6.0.0 -testSqlCoerce - :: forall arg result - . ( Typeable arg, PersistFieldSql arg - , Typeable result, PersistFieldSql result - , SqlCoerce arg result - ) - => Either (TypeRep, TypeRep) () -testSqlCoerce = - if sqlType (Proxy @arg) == sqlType (Proxy @result) - then pure () - else Left (typeRep (Proxy @arg), typeRep (Proxy @result)) - -- | Folks often want the ability to promote a Haskell function into the -- 'SqlExpr' expression language - and naturally reach for 'fmap'. -- Unfortunately, this is impossible. We cannot send *functions* to the