groundhog
groundhog copied to clipboard
better sharded DB support
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.
I have an idea to write a wrapper for backend, to modify table name there, but I struggle with forwarding existed functions.
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.