Open FintanH opened 6 years ago
If you'd like to get a PR together then we can track discussion in that instead :)
Might not be related to this issue itself, but if the other is searching on how to use "Materialized Views" with esqueleto, this is what I do.
-- In a query file
messagesWithFilterProfileIds :: SqlQuery ...
messagesWithFilterProfileIds = ...
-- In a db type file
share [mkPersist sqlSettings] [persistLowerCase|
MessagesWithProfileIds sql=messages_with_filter_profile_ids
messageId MessageId
...
deriving Eq Ord Show
|]
-- In migration
createView_messagesWithFilterProfileIds :: MonadUnliftIO m => SqlPersistT m ()
createView_messagesWithFilterProfileIds = do
(query, params) <- renderQueryToText SELECT messagesWithFilterProfileIds
rawExecute ("DROP MATERIALIZED VIEW IF EXISTS messages_with_filter_profile_ids") params
rawExecute ("CREATE MATERIALIZED VIEW messages_with_filter_profile_ids as " <> query) params
migrate :: MonadUnliftIO m => SqlPersistT m ()
migrate = do
runMigration migration
_ <- createView_messagesWithFilterProfileIds
pure ()
Flesh out materialized views started on
bitemyapp/materialized-view-example