yesodweb / persistent

Persistence interface for Haskell allowing multiple storage methods.
MIT License
462 stars 293 forks source link

Is there shareded DB support? #1130

Open yaitskov opened 3 years ago

yaitskov commented 3 years ago

Hi,

It seems Persistent doesn't support sharded tables. The situation when a single DB has lots of tables with same structure. All these tables share a data type representing the tables, which instantiates PersistEntity class.

PersistEntity has entitfyDef function. It already returns meta data including table name, but there is not way to make it dynamic. entityDef is pure function so it is not possible to benefit from ReaderT.

parsonsmatt commented 3 years ago

Usually sharding/partitioning is handled by the database layer, using a plugin or similar. As far as SQL is concerned, you usually just have a single "table" that you query and the database handles the underlying stuff. If you handle it like this, then Persistent "just works." I would see if this can work out for you.

If you must have multiple database tables that all share the exact same structure, then you should probably have multiple Persistent entities - one for each table. Persistent is meant to be a relatively direct translation of your database schema.