bitemyapp / esqueleto

New home of Esqueleto, please file issues so we can get things caught up!
BSD 3-Clause "New" or "Revised" License
370 stars 107 forks source link

Add pgcrypto functions #256

Closed 3kyro closed 2 years ago

3kyro commented 3 years ago

Hi, I have a local implementation of the following functions from the pgcrypto module:

toCrypt :: SqlString s => Algorithm -> s -> SqlExpr (Value s)
fromCrypt :: SqlString s => SqlExpr (Value s) -> s -> SqlExpr (Value Bool)

Usage with a contrived example would be:

-- insert a User
insertSelect $
    User
      <# val "new_user"
      <&> toCrypt BF "1234Password"
      -- etc

-- validate a User
select $ do
    user <- from $ Table @User
    where_ $ user ^. UserName ==. val "new_user"
      &&. fromCrypt (user ^. UserPassword) "1234Password"
    pure user

I was wondering if they can be included in esqueleto - in the PostgreSQL module - or it's better of to create an external library.

If inclusion to esqueleto is OK I'd happily submit a PR

3kyro commented 3 years ago

Actually going through #228, I'll wait for it to be merged since I am pattern matching against the SqlExpr constructors.

belevy commented 3 years ago

@3kyro sorry about the change causing rework on your side. Id be happy to see a PR for the crypto functions.

3kyro commented 3 years ago

@belevy No problem at all. Thanks for the confirmation, I'll submit a PR for this shortly

3kyro commented 2 years ago

I'm closing this issue as there was no agreement on the proposed API.