nurpax/sqlite-simple

Re-export underlying direct-sqlite Database instead of wrapping it

IreneKnapp opened this issue · 4 comments

So, I'm pondering an addition to direct-sqlite. Specifically, I'd like to wrap the online-backup API that SQLite provides. I realized when I started thinking about how to integrate this into my code that if I've opened the connection with sqlite-simple, there's no way to use the lower-level primitives on it, and vice-versa, there's no way to open in low-level mode (perhaps to do some schema initialization or somesuch) and switch to high-level later on.

I could see a case to be made that this separation is by design, that sqlite-simple's goal is to hide these messy details. If so, oh well I guess, but it would be a nice ability!

Assuming we're on the same page that it's something you'd like, the simplest way to correct this would be by making Connection be a type synonym for Database, or else to remove Connection altogether and just use Database everywhere. I can see how it made sense initially to wrap it, when it wasn't clear whether sqlite-simple would need more per-connection state, but the library is mature now and it seems clear that it doesn't.

I'm more than happy to write the patch, but of course this is your project, so I wanted to get pre-approval before spending time on it.

Thanks in advance!

Yes, I intentionally hid it. But I can see that it's possible to run into situations where one'd like to use something from direct-sqlite that's not exposed via sqlite-simple. I did at some point have some plans on perhaps doing some caching at Connection level and these would break if users are able to break down to the lower level API. That said, it's quite unlikely that any such magic will be added.

I'd still like to discourage mixing these APIs and would like this to show in types, so perhaps the change should be such that:

-- | Connection to an open database.
data Connection = Connection Base.Database

change this to

-- | Connection to an open database.
newtype Connection = Connection { connectionHandle :: Base.Database }

and export it from Database.SQLite.Simple as

  Connection(..)

this allows constructing sqlite-simple Connections from a direct-sqlite handle and vice versa, allows for dropping down to direct-sqlite from an sqlite-simple Connection.

If there's something you often need from direct-sqlite that's not conveniently/efficiently done from sqlite-simple level, then we should also consider adding this functionality into the sqlite-simple API.

Discouraging the mixing makes sense to me. Okay, I'll write the patch most likely tomorrow. Thanks!

Yes, I will absolutely open separate issues for any frequent needs!

@IreneKnapp I needed to release a new version due to some Lazy Text instances I added which snaplet-sqlite-simple needs, so I just went ahead and added your feature while at it. It was not a big change :)

Cool, thanks! :)