Skip to content

Conversation

@ncruces
Copy link
Contributor

@ncruces ncruces commented Oct 20, 2025

Description

Avoids unnecessarily importing the modernc SQLite driver.
The package is still imported by the main and test packages that need it.

Motivation and Context

Library users (such as the VFS) don't need to import the driver, which registers it on init.

See #772 (comment)

For example, the package used by the current prototype vfs.go is meant to work with cgo drivers, not modernc:

"github.com/psanford/sqlite3vfs"

In fact, I'm not sure a VFS can be implemented for modernc. My reading of their vfs package says no, but I'm sure with some effort, dropping down to the lower level allows it.

How Has This Been Tested?

I've tested the litestream command, and it works, which is expected, as it imports modernc and thus registers the driver (i.e., no change):

_ "modernc.org/sqlite"

All tests pass, as both the litestream_test package, and testingutil import the driver.

Library clients will have themselves to import modernc: AFAICT if they use litestream.DB, litestream.Replica or litestream.Store.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (would cause existing functionality to not work as expected)

This may break library users. It's a simple fix, though, just add this somewhere in their code:

import _ "modernc.org/sqlite"

Checklist

  • My code follows the code style of this project (go fmt, go vet)
  • I have tested my changes (go test ./...)
  • I have updated the documentation accordingly (if needed)

I haven't updated docs. Where would docs for library users be? This should probably me mentioned in release notes.

@ncruces
Copy link
Contributor Author

ncruces commented Nov 9, 2025

I can achieve close to the same with a replace directive:
https://github.com/ncruces/go-sqlite3/blob/8f9a6ca/litestream/go.mod#L63

But it's not as good. The upshot is that with a small change in my driver, Litestream seems to work fine based entirely on my driver (not that switching is a good idea, it's not):
https://github.com/ncruces/go-sqlite3/blob/8f9a6ca/driver/driver.go#L445-L459

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.

1 participant