Skip to content

Expose underlying raw SQLite database pointer. - #772

Merged
parsonsmatt merged 5 commits into
yesodweb:masterfrom
merijn:raw-sqlite-ptr
Jul 17, 2019
Merged

parsonsmatt merged 5 commits into
yesodweb:masterfrom
merijn:raw-sqlite-ptr

Conversation

@merijn

@merijn merijn commented Jan 12, 2018 •

Copy link
Copy Markdown
Contributor

Allows people to use the FFI to call SQLite's C API functions. Fixes #771.

Before submitting your PR, check that you've:

After submitting your PR:

  • Update the Changelog.md file with a link to your PR
  • Check that CI passes (or if it fails, for reasons unrelated to your change, like CI timeouts)

@merijn merijn changed the title Expose underlying raw SQLite database pointer. Fixes #771 Expose underlying raw SQLite database pointer. Jan 12, 2018
@MaxGabriel

Copy link
Copy Markdown
Member

LGTM so far!

@MaxGabriel

Copy link
Copy Markdown
Member

(Just needs a change log update for merge)

@merijn

merijn commented Jan 16, 2018

Copy link
Copy Markdown
Contributor Author

@MaxGabriel I'll add a changelog soon, I'm also experimenting with variations of withSqliteConn & co that make it easier to actually access the Connection. I'm still playing what works nicest in my code, probably something along the lines of withSqliteConn :: (MonadBaseControl IO m, MonadIO m, MonadLogger m, IsSqlBackend backend) => Text -> (Connection -> backend -> m a) -> m a (not sure whether that should just go into Database.Persist.Sqlite or into a separate Database.Persist.Sqlite.Internal). Anyway, I'm also dealing with a paper deadline, so I will probably finalise this PR and add a change log somewhere next week after the paper demon has been slain.

@merijn
merijn force-pushed the raw-sqlite-ptr branch 3 times, most recently from ff0acb6 to 859b696 Compare February 16, 2018 15:18
@merijn

merijn commented Feb 16, 2018

Copy link
Copy Markdown
Contributor Author

Ok, so I finally had time to get back to this. I added a RawSqlite type and corresponding withRawSqliteConnInfo that packs up the Sqlite.Connection with the persistent SqlBackend. So that it's easier to run a persistent monad and still have access to the pointer via Database.Sqlite.Internal.

I implemented all the relevant PersistCore, PersistStoreRead, etc. classes too (via liftPersist), so it should be possible to just directly use ReaderT (RawSqlite SqlBackend) as drop-in for ReaderT SqlBackend.

I'm not very opinionated about the names of types/fields, because I suck at coming up with them, so feel free to suggest better ones.

Also, I could migrate the new functionality to a new Database.Persist.Sqlite.Internal module, but that would've required moving a bunch of the existing code and then importing it back, which seemed like a hassle, but if that's preferred I can change it.

@merijn

merijn commented Feb 17, 2018 •

Copy link
Copy Markdown
Contributor Author

If people support the change suggested in #783 this PR might have to wait those changes get in so I can add a withRawSqlitePoolInfo variant too.

@MaxGabriel

Copy link
Copy Markdown
Member

@merijn I think you mean #783

@merijn

merijn commented Feb 17, 2018

Copy link
Copy Markdown
Contributor Author

@MaxGabriel whoops, yeah.

@merijn

merijn commented Feb 18, 2018

Copy link
Copy Markdown
Contributor Author

@MaxGabriel besides waiting for what to do with #783 is there anything you'd like to see changed/named differently/organised about this? (I'd like to at least settle on the names/modules so I can commit to them in my own code, regardless of when this gets merged/released)

@MaxGabriel

Copy link
Copy Markdown
Member

@merijn Yeah this looks good to me, the only thing I would ask to change is can you export separate functions for the RawSqlite constructor? The approach here https://www.snoyman.com/blog/2016/11/designing-apis-for-extensibility or the lens approach used in the main SQLite module are OK. Sorry this isn't documented anywhere—Persistent recently is trying to do new constructors this way

@MaxGabriel

Copy link
Copy Markdown
Member

(If anyone else wants to take a look at this now would be a good time)

@parsonsmatt

Copy link
Copy Markdown
Collaborator

#886 has been merged via #893, so work on this can resume with a bit more productivity I hope :)

@parsonsmatt

Copy link
Copy Markdown
Collaborator

@merijn This PR looks great! once you've resolved merge conflicts (should be fairly straightforward) then we can get this released 😄

@merijn

merijn commented May 20, 2019

Copy link
Copy Markdown
Contributor Author

@parsonsmatt I'll update this "Real Soon (TM)" (it'll have to wait until I'm done moving)

@merijn merijn closed this Jul 15, 2019
@merijn
merijn deleted the raw-sqlite-ptr branch July 15, 2019 12:10
@merijn merijn reopened this Jul 15, 2019
@merijn

merijn commented Jul 15, 2019

Copy link
Copy Markdown
Contributor Author

Finally getting around to reviving this. Still have to figure out how to fit the code with the revamped typeclasses, so consider this a work-in-progress.

@merijn

merijn commented Jul 15, 2019

Copy link
Copy Markdown
Contributor Author

Ok, I think that's everything? Seems like it needed less work than I thought.

@parsonsmatt I think this should be good to merge (assuming the tests don't unexpectedly break).

@merijn

merijn commented Jul 15, 2019

Copy link
Copy Markdown
Contributor Author

Incidentally, who is responsible for maintaining/merging PRs for persistent-sqlite (and persistent-template)?

I've got a few other (super simple) patches that fix minor warts/problems lying around to PR, but I'm unsure who to ping to get them looked at, since some of the PR seem to take quite a while to get noticed and I'd prefer to finish upstreaming them in less than 1.5 years ;)

@parsonsmatt

Copy link
Copy Markdown
Collaborator

@merijn I'm helping out with it where I can, though I ping @snoyberg for anything more involved as I don't use SQLite much. I'll take a look at this today, thanks!

@parsonsmatt parsonsmatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dig it, looks great! 😄

@parsonsmatt

Copy link
Copy Markdown
Collaborator

I am, however, pre-caffeinated, so I am going to take another peek in an hour or two before merging.

@parsonsmatt

Copy link
Copy Markdown
Collaborator

OK, so on a first pass, this looks great. Can you add a test or test-suite that will ensure that this new Connection type works with all the existing functionality?

@merijn

merijn commented Jul 15, 2019

Copy link
Copy Markdown
Contributor Author

OK, so on a first pass, this looks great. Can you add a test or test-suite that will ensure that this new Connection type works with all the existing functionality?

Do you mean the RawSqlite type? The Connection type is completely unchanged, it's just been moved from Database.Sqlite to Database.Sqlite.Internal so that the constructor can be exported.

@parsonsmatt

Copy link
Copy Markdown
Collaborator

Yes, that's right - I was typing from memory, my bad.

In retrospect I think having it satisfy all the class instances from persistent should do it. I'll review the code again and see if there's aynthing missing.

@parsonsmatt
parsonsmatt merged commit c1111ca into yesodweb:master Jul 17, 2019
@merijn
merijn restored the raw-sqlite-ptr branch March 16, 2020 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Export Connection constructor from persistent-sqlite's Database.Sqlite

3 participants