IreneKnapp / direct-sqlite

MIT License
35 stars 54 forks source link

Add modules to direct-sqlite for lower-level access #12

Closed joeyadams closed 12 years ago

joeyadams commented 12 years ago

Sorry, this is a pretty big pull request. The commits trace the development history, which is basically:

This pull request renames SQLite3.hsc to SQLite3.hs, which makes the diff a bit less useful. To see what changed in Database.SQLite3, you can do the following:

git remote add joeyadams git://github.com/joeyadams/direct-sqlite.git
git fetch joeyadams
git diff 84efb91:Database/SQLite3.hsc b312202:Database/SQLite3.hs

This pull request includes the commit by @nurpax from pull request #9, with the merge conflict resolved.

What this pull request does

This splits direct-sqlite into three levels of abstraction:

My goal was to avoid breaking the existing API, so people can start using the new internals without compatibility issues. However, some minor changes have been made to the existing API:

I took plenty of liberties with Database.SQLite3.Direct. It represents the direction I would like to see Database.SQLite3 go, namely:

I'd also want to factor the Error type:

data Result
    = Okay
    | StepResult    !StepResult
    | Error         !Error

    -- Extended error types; see http://www.sqlite.org/c3ref/c_abort_rollback.html
    | ErrorIO       !ErrorIO
    | ErrorLocked   !ErrorLocked
    | ErrorBusy     !ErrorBusy
    | ErrorCantOpen !ErrorCantOpen
    | ErrorCorrupt  !ErrorCorrupt
    | ErrorReadOnly !ErrorReadOnly
    | ErrorAbort    !ErrorAbort

But we'd have to remove these data constructors from Error:

IreneKnapp commented 12 years ago

Just for the record, if you use git mv in future, it preserves history on the file. I'm now reading through this all!

joeyadams commented 12 years ago

Just for the record, if you use git mv in future, it preserves history on the file.

Unfortunately, that's not true: http://stackoverflow.com/questions/1094269/whats-the-purpose-of-git-mv

That is, unless they changed it in a recent version of git. In any case, thanks for putting up with my shenanigans.

IreneKnapp commented 12 years ago

Just as a comment, we made a breaking API change so recently (the switch to Text, with 2.0) that I'm not worried about a second one. So you should probably go ahead and add any changes that you'd like to make "when we're ready to break things".

joeyadams commented 12 years ago

Just as a comment, we made a breaking API change so recently (the switch to Text, with 2.0)

Wow, only five days ago. I didn't realize it was that recent.

So you should probably go ahead and add any changes that you'd like to make "when we're ready to break things".

I'd be happy to. In any case, since no functions in Database.SQLite3 currently take or return an 'Error', I doubt changing it will cause compatibility issues.

nurpax commented 12 years ago

I won't mind any API breaking changes in direct-sqlite, but if you do break the existing API, please bump up the version number to 2.1 so that I can protect sqlite-simple and snaplet-sqlite-simple with a version upper bound.

IreneKnapp commented 12 years ago

Yes, naturally. Don't worry!

On Mon, Aug 20, 2012 at 3:13 AM, Janne Hellsten notifications@github.comwrote:

I won't mind any API breaking changes in direct-sqlite, but if you do break the existing API, please bump up the version number to 2.1 so that I can protect sqlite-simple and snaplet-sqlite-simple with a version upper bound.

— Reply to this email directly or view it on GitHubhttps://github.com/IreneKnapp/direct-sqlite/pull/12#issuecomment-7862237.

-- Irene Knapp

joeyadams commented 12 years ago

Actually, I decided not to break down the error code enumeration (data Result = ...). I see it as a lot of work, with very little benefit:

One thing I would like to break, though, is the name of bind:

bind :: Statement -> [SQLData] -> IO ()

Unlike column, which only reads one column, bind sets all the parameters. Here's what I'd like to do instead:

bind :: Statement -> ParamIndex -> SQLData -> IO ()
binds :: Statement -> [SQLData] -> IO ()

This should also make it easier for people to implement named parameters in their higher-level libraries.

joeyadams commented 12 years ago

@IreneKnapp: Have you finished reviewing this pull request yet? I plan to improve the API of Database.SQLite3 itself, but the commits will be based on the ones in this pull request.

IreneKnapp commented 12 years ago

Sorry it's taking so long! I want to understand it, not just rubber-stamp it. It's fairly invasive and if I don't keep myself current with what's going on in the codebase, I'll cease to understand it, you know? Hopefully tonight.

IreneKnapp commented 12 years ago

(If I conclude that I'm never going to get the time, then I will just rubber-stamp it, just to be clear. That's the only thing that would be fair. I'm aware that this phase when you've done the work and are waiting to hear back is pretty frustrating. But right now I expect to have time.)

IreneKnapp commented 12 years ago

I guess I'll just trust that your notes are accurate rather than reading and understanding the code. I feel like I've kept you waiting too long already.