Skip to content

Conversation

ncruces
Copy link
Contributor

@ncruces ncruces commented May 28, 2025

As discussed on Reddit, and as a first approximation, this is what should be required to support my driver.

What's the simplest, but still realistic, way to test this? I ask because my driver has a few peculiarities, and I'd like to be sure I'm not messing anything up.

The one that matters the most here, is that the driver is split into 3 packages:

You don't need to import driver or embed everywhere in your project, and in fact I'd argue if you're creating (or in this case generating) a library you shouldn't import them at all.

The reason is that, e.g., for the embed package in particular, you may decide to embed/link a modified SQLite build. I have an alternative package that includes "experimental" SQLite features, Alex publishes another one that supports vector search, etc.

It's up to the final end user which build of SQLite they want to link with, and they can decide by importing the correct package in the main.go of their application (or some other place where it makes sense).

I'm sorry if this over complicates things.

@stephenafamo
Copy link
Owner

Right now, the way to test would be to setup a project locally, generate code for an example schema (that includes unique constraints) and then run the generated tests.

You will have to supply a testDB so that the tests requiring a database connection are not skipped.
You can use test/gen/templates/database.bob_test.go.tpl as an example, but this template is only added during tests.

I should extend the tests to run for each driver combination, right now it only runs for the default drivers.

Speaking of, I'm not sure if your driver supports attaching databases and how that should ideally be done.

@stephenafamo
Copy link
Owner

I've just made a push to main to extend testing for multiple drivers.

You should add your driver to gen/bobgen-sqlite/driver/sqlite_test.go:162 and make the required changes to the test DB template at test/gen/templates/database.bob_test.go.tpl

If everything passes, it should be all good 👍🏾

@stephenafamo
Copy link
Owner

Made even more changes to prevent using an unsupported driver.

You should update the switch in gen/bobgen-sqlite/driver/sqlite.go:45 to not panic if your driver is configured.

Also, kindly update CHANGELOG.md with your changes, including a (thanks @ncruces) at the end of the item

@stephenafamo stephenafamo merged commit 22a1ea2 into stephenafamo:main May 29, 2025
8 checks passed
@joeblew999
Copy link

joeblew999 commented Jun 4, 2025

Thanks @ncruces and @stephenafamo

this is so useful .

SQLite rsync also now works too .

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.

3 participants