rvv041 - Insert and edit an address book entry functions created

address field in address book changed to T.Text
This commit is contained in:
Rene V. Vergara A. 2024-05-13 16:26:07 -04:00
parent 2fb6747bfb
commit e9e56453c1

View file

@ -249,7 +249,7 @@ share
AddressBook AddressBook
network ZcashNetDB network ZcashNetDB
descrip T.Text descrip T.Text
address HexStringDB address T.Text
UniqueABA address UniqueABA address
deriving Show Eq deriving Show Eq
|] |]
@ -1484,5 +1484,24 @@ getAdrBook pool n =
where_ (adrbook ^. AddressBookNetwork ==. val (ZcashNetDB n)) where_ (adrbook ^. AddressBookNetwork ==. val (ZcashNetDB n))
pure adrbook pure adrbook
-- | Save a new address into AddressBook
saveAdrsInAdrBook ::
ConnectionPool -- ^ The database path to use
-> AddressBook -- ^ The address to add to the database
-> IO (Maybe (Entity AddressBook))
saveAdrsInAdrBook pool a =
runNoLoggingT $
PS.retryOnBusy $ flip PS.runSqlPool pool $ insertUniqueEntity a
-- | Update an existing address into AddressBook
updateAdrsInAdrBook :: ConnectionPool -> T.Text -> AddressBookId -> IO ()
updateAdrsInAdrBook pool a i = do
runNoLoggingT $
PS.retryOnBusy $
flip PS.runSqlPool pool $ do
update $ \ab -> do
set ab [AddressBookAddress =. val a]
where_ $ ab ^. AddressBookId ==. val i
rmdups :: Ord a => [a] -> [a] rmdups :: Ord a => [a] -> [a]
rmdups = map head . group . sort rmdups = map head . group . sort