Skip to content

Commit

Permalink
make function processing sql rows module-level (#533)
Browse files Browse the repository at this point in the history
  • Loading branch information
epoberezkin committed Sep 22, 2022
1 parent 41d3c14 commit f8505d4
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/Simplex/Messaging/Agent/Store/SQLite.hs
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,14 @@ sqlString s = quote <> T.replace quote "''" (T.pack s) <> quote
exexSQL :: DB.Connection -> Text -> IO [Text]
exexSQL db query = do
rs <- newIORef []
SQLite3.execWithCallback (DB.connectionHandle db) query (addRow rs)
SQLite3.execWithCallback (DB.connectionHandle db) query (addSQLResultRow rs)
reverse <$> readIORef rs

addSQLResultRow :: IORef [Text] -> SQLite3.ColumnIndex -> [Text] -> [Maybe Text] -> IO ()
addSQLResultRow rs _count names values = modifyIORef' rs $ \case
[] -> [showValues values, T.intercalate "|" names]
rs' -> showValues values : rs'
where
addRow rs _count names values = modifyIORef' rs $ \case
[] -> [showValues values, T.intercalate "|" names]
rs' -> showValues values : rs'
showValues = T.intercalate "|" . map (fromMaybe "")

checkConstraint :: StoreError -> IO (Either StoreError a) -> IO (Either StoreError a)
Expand Down

0 comments on commit f8505d4

Please sign in to comment.