persistent-typed-db
persistent-typed-db copied to clipboard
Read-only `SqlFor`
I'm looking at introducing this library to a codebase at work, where the application environment stores a separate Pool SqlReadBackend for read-only queries. Is there a way to use this library to also enforce that these queries are used with the right schema? I think it would be possible to replace the pool with a ConnectionPoolFor MainDb and then convert it to a read-only pool inside a runReadQueryMainDb function, but that would be slightly less type-safe, since nothing then stops you from bypassing that function and using the pool for write queries anyway.
but that would be slightly less type-safe, since nothing then stops you from bypassing that function and using the pool for write queries anyway.
There's not anything I can do as a library author to prevent that, either. Even in persistent itself, there are "unsafe" functions for forgetting a read-only restriction and promoting to a write-capable pool. The best trick is to probably use hlint to ban these unsafe functions (whether defined in your app or somewhere else).