groundhog icon indicating copy to clipboard operation
groundhog copied to clipboard

better sharded DB support

Open yaitskov opened this issue 3 years ago • 2 comments

Hi,

Groundhog doesn't supported sharded tables well. i.e the situation when DB has lots of tables with same structure. All these tables share a data type representing the tables, which instantiates PersistentEntity class.

PersistentEntity has entitfyDef function. It already returns meta data including table name, but there is not way to deliver table name to PersistentEntity in case of reading data from DB. e.g.

   all :: [MyType] <- select CondEmpty

MyType represents multiple tables: my_type_1, my_type_2, ....

entityDef is pure function so it is not possible to benefit from ReaderT. ThreadLocal feature is deprecated in Haskell.

yaitskov avatar Sep 27 '20 21:09 yaitskov

I have an idea to write a wrapper for backend, to modify table name there, but I struggle with forwarding existed functions.

yaitskov avatar Sep 28 '20 16:09 yaitskov

The place where entityDef is used is at https://github.com/lykahb/groundhog/blob/master/groundhog/Database/Groundhog/Generic/PersistBackendHelpers.hs Those functions are in the Action monad. You can change them to a more general monad that has connection.

lykahb avatar Sep 30 '20 17:09 lykahb