persistent-typed-db icon indicating copy to clipboard operation
persistent-typed-db copied to clipboard

Read-only `SqlFor`

Open isomorpheme opened this issue 3 years ago • 1 comments

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.

isomorpheme avatar Apr 04 '22 12:04 isomorpheme

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).

parsonsmatt avatar Apr 04 '22 13:04 parsonsmatt