Skip to content

Conversation

@wdullaer
Copy link
Contributor

Sqlite has become widely used in our ecosystem.
This module moves the common boilerplate and best practices into a central place.

@imiric imiric self-requested a review December 24, 2025 15:00
Copy link
Member

@arapaho arapaho left a comment

Choose a reason for hiding this comment

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

🎄 thanks!

Copy link
Member

@imiric imiric left a comment

Choose a reason for hiding this comment

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

Very nice, thank you! 🙇

I'm still getting used to the fx way of doing things, so most of my feedback is related to that. The rest are nitpicks and minor suggestions.

I appreciate the example, and being able to run migrations on startup. 👍

I'll integrate this in firewall as soon as it's merged.

@wdullaer wdullaer force-pushed the push-vukxpqozslzz branch 4 times, most recently from fe435b0 to 9cc6bc5 Compare December 29, 2025 15:26
@imiric
Copy link
Member

imiric commented Jan 2, 2026

@wdullaer Is there anything pending here, or can it be merged?

We'd like to integrate this in firewall, though it's not urgent.

Copy link
Member

@Fumesover Fumesover left a comment

Choose a reason for hiding this comment

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

Any reason to diverge from the fxXXXX naming scheme for modules? I would have expected fxsqlite instead of just sqlite

if sqliteConf.busyTimeout != time.Duration(0) {
conn.SetBusyTimeout(sqliteConf.busyTimeout)
}
return sqlitex.ExecuteTransient(conn, "PRAGMA foreign_keys = ON;", &sqlitex.ExecOptions{})
Copy link
Member

Choose a reason for hiding this comment

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

Is this used anywhere in our repositories? I'm not seeing this in the pidx creation for blobd

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's used in firewall.
Sqlite disables this by default for backwards compatibility. It's kind of hidden footgun these modules are intended to prevent.

Copy link
Contributor

@aureliar8 aureliar8 left a comment

Choose a reason for hiding this comment

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

I'm not sure this attempt at homogenizing our sqlite practice is the right one. Mostly because I don't think this is the correct driver/API that we want to expose for the next project that uses sqlite.

Let's recap what we use atm at exoscale:

  • Blobd uses zombiezen.com/go/sqlite/sqlitex because we need very high speed sqlite operation and thus can't use the slower database/sql API (we need control on memory allocation)
  • I think firewall-agent also uses zombiezen.com/go/sqlite/sqlitex, but why chose this one instead of the regular mattn/sqlite3 driver that is API compatible with the database/sql interface
  • Nbdagent uses mattn/sqlite3 to get a databse/sql-compatible driver and then uses jmoiron/sqlx as the query lib
  • compute-agent uses mattn/sqlite3 to get a databse/sql-compatible driver and then uses gorm as the query lib
  • blobd-orchestrator uses mattn/sqlite3 to get a databse/sql-compatible driver and then uses gorm as the query lib
  • warp uses mattn/sqlite3 to get a databse/sql-compatible driver and then uses gorm as the query lib

Blobd-orchestrator & compute-agent will not be able to use this without major rewrite (or never at all for blobd-orchestrator because we use gorm to abstract sqlite/mysql differences)

Maybe we should rather

  • Make stelling provide a database/sql-compatible dirver
  • Change firewall-agent to use this API
  • Converge on this expect for blobd that has very specific performance characteristics ?

WDYT ?

@wdullaer
Copy link
Contributor Author

wdullaer commented Jan 9, 2026

I think the list here shows that some standardisation is needed.

I suppose the way forward is the approach we took with the migration library: we support both.
I think the API of the module can be the same, with the only difference being whether you get an stdlib sql.DB or an sqlitex Pool.

I'll update this PR to move the existing code into a fxsqlite package for naming consistency.
I'll add support for sql.DB in a follow up PR.

@aureliar8
Copy link
Contributor

That's fine for me, and let's clearly document from a glance that the sql.DB is the simplest one to use and that sqlitex.Pool is reserved for advances usecases

Sqlite has become widely used in our ecosystem.
This module moves the common boilerplate and best practices into a
central place.
@wdullaer
Copy link
Contributor Author

wdullaer commented Jan 9, 2026

Since this hasn't merged yet, I added the sql.DB support here, in its own commit.

Additionally the module also provides a gorm.DB if needed.
The module API is identical to the sqlitex one, to make it easier to
swap out if the requirements change and require the higher performing
driver.
@wdullaer wdullaer merged commit 119d42e into master Jan 20, 2026
5 checks passed
@wdullaer wdullaer deleted the push-vukxpqozslzz branch January 20, 2026 12:41
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.

6 participants