esqueleto-pgcrypto: Esqueleto support for the pgcrypto PostgreSQL module

[ bsd3, database, library ] [ Propose Tags ] [ Report a vulnerability ]

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0
Change log ChangeLog.md
Dependencies base (>=4.13 && <5), esqueleto (>=3.5.2.2 && <3.6), text (>=1.2.4.1 && <1.3) [details]
License BSD-3-Clause
Copyright 2021 Kyriakos Papachrysanthou
Author Kyriakos Papachrysanthou
Maintainer papachrysanthou.k@gmail.com
Category Database
Home page https://github.com/3kyro/esqueleto-pgcrypto#readme
Bug tracker https://github.com/3kyro/esqueleto-pgcrypto/issues
Source repo head: git clone https://github.com/3kyro/esqueleto-pgcrypto
Uploaded by 3kyro at 2021-10-06T12:07:01Z
Distributions
Downloads 163 total (6 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
All reported builds failed as of 2021-10-06 [all 1 reports]

Readme for esqueleto-pgcrypto-0.1.0.0

[back to package description]

esqueleto-pgcrypto

Esqueleto support for the pgcrypto PostgreSQL module

share
    [mkPersist sqlSettings]
    [persistLowerCase|
    UserAccount json
        name T.Text
        UniqueName name
        passwordHash T.Text
        deriving Show Read Eq

-- insert a `PersistField` using pgcrypto's `crypt` function for password hashing
insertUserAccount = insertSelect $ 
    pure $
        UserAccount
            <# val "username"
            <&> toCrypt (BF Nothing) "1234password"

login name pwd = select $ do
    user <- from $ Table UserAccount
    where_ $ user ^. UserAccountName ==. val name
        &&. fromCrypt (user ^. UserAccountPasswordHash) pwd
    pure user

Tests

To run tests you will need a pgctest named postgresql database listening on port 5432.

The connection details are

"host=localhost port=5432 user=pgctest password=pgctest dbname=pgctest"

You can crete this instace as follows:

$ sudo -u postgres createuser --superuser pgctest 
$ sudo -u postgres createdb pgctest
$ sudo -u postgres psql
# set the password of pgctest to pgctest
postgres=# \password pgctest