[PR #530] [MERGED] refactor: switch SQLite driver to pure-Go implementation #748

Open
opened 2025-10-07 00:21:42 +03:00 by OVERLORD · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/pocket-id/pocket-id/pull/530
Author: @ItalyPaleAle
Created: 5/14/2025
Status: Merged
Merged: 5/14/2025
Merged by: @stonith404

Base: mainHead: sqlite-pure-go


📝 Commits (3)

  • 794bc0c refactor: switch SQLite driver to pure-Go implementation
  • 7a50f1b Disable CGO
  • 4534fa6 Update scan

📊 Changes

8 files changed (+248 additions, -23 deletions)

View changed files

📝 Dockerfile (+1 -1)
📝 backend/go.mod (+13 -5)
📝 backend/go.sum (+46 -8)
📝 backend/internal/bootstrap/db_bootstrap.go (+54 -4)
backend/internal/bootstrap/db_bootstrap_test.go (+121 -0)
📝 backend/internal/common/env_config.go (+1 -1)
📝 backend/internal/model/types/date_time.go (+11 -3)
📝 backend/internal/service/app_config_service_test.go (+1 -1)

📄 Description

This PR changes the driver used to connect to SQLite to github.com/glebarez/sqlite.

The main difference with the previous driver (gorm.io/driver/sqlite) is that the new one uses a pure-Go implementation of SQLite based on modernc.org/sqlite.

There are three main benefits with making this change:

  1. It makes it possible to build Pocket ID with CGo disabled, which means that cross-compilation (building for different archs or OS's) becomes a lot simpler, requiring nothing more than the standard Go compiler
  2. Binaries are fully statically-compiled, with no dependency on libc. This makes it simpler to run across all Linux distributions, even those that use different libc implementations (like Alpine)
  3. It helps with a possible future goal of running on distroless containers

The pure-Go driver is slightly slower, more noticeable with very large databases, larger than Pocket ID users are expected to have.

The modernc.org/sqlite package is built by "transpiling" the C library into Go code, and they have extensive test suites to ensure the behavior is consistent. The same package is used by many apps successfully in production, so stability shouldn't be a concern.

The "biggest" user-facing change is that github.com/mattn/go-sqlite3 supports some additional args in the query string which need to be converted to PRAGMA statements with the modernc.org/sqlite package. To avoid confusing users (and potentially introducing yet another breaking change), I've added a function that converts the common query string args into the format supported by the modernc package. Most users would not need to worry about it, as wery few should change the DB connection string.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/pocket-id/pocket-id/pull/530 **Author:** [@ItalyPaleAle](https://github.com/ItalyPaleAle) **Created:** 5/14/2025 **Status:** ✅ Merged **Merged:** 5/14/2025 **Merged by:** [@stonith404](https://github.com/stonith404) **Base:** `main` ← **Head:** `sqlite-pure-go` --- ### 📝 Commits (3) - [`794bc0c`](https://github.com/pocket-id/pocket-id/commit/794bc0cc305409d4934a81b8eb61277ae943efc1) refactor: switch SQLite driver to pure-Go implementation - [`7a50f1b`](https://github.com/pocket-id/pocket-id/commit/7a50f1bd670eca037b4c64f8a2b3ffc37432f6c2) Disable CGO - [`4534fa6`](https://github.com/pocket-id/pocket-id/commit/4534fa69c16a1d0a99dc00b75aa62e27d144959c) Update scan ### 📊 Changes **8 files changed** (+248 additions, -23 deletions) <details> <summary>View changed files</summary> 📝 `Dockerfile` (+1 -1) 📝 `backend/go.mod` (+13 -5) 📝 `backend/go.sum` (+46 -8) 📝 `backend/internal/bootstrap/db_bootstrap.go` (+54 -4) ➕ `backend/internal/bootstrap/db_bootstrap_test.go` (+121 -0) 📝 `backend/internal/common/env_config.go` (+1 -1) 📝 `backend/internal/model/types/date_time.go` (+11 -3) 📝 `backend/internal/service/app_config_service_test.go` (+1 -1) </details> ### 📄 Description This PR changes the driver used to connect to SQLite to `github.com/glebarez/sqlite`. The main difference with the previous driver (`gorm.io/driver/sqlite`) is that the new one uses a pure-Go implementation of SQLite based on `modernc.org/sqlite`. There are three main benefits with making this change: 1. It makes it possible to build Pocket ID with CGo disabled, which means that cross-compilation (building for different archs or OS's) becomes a lot simpler, requiring nothing more than the standard Go compiler 2. Binaries are fully statically-compiled, with no dependency on libc. This makes it simpler to run across all Linux distributions, even those that use different libc implementations (like Alpine) 3. It helps with a possible future goal of running on distroless containers The pure-Go driver is slightly slower, more noticeable with very large databases, larger than Pocket ID users are expected to have. The `modernc.org/sqlite` package is built by "transpiling" the C library into Go code, and they have extensive test suites to ensure the behavior is consistent. The same package is used by many apps successfully in production, so stability shouldn't be a concern. The "biggest" user-facing change is that `github.com/mattn/go-sqlite3` supports some additional args in the query string which need to be converted to PRAGMA statements with the `modernc.org/sqlite` package. To avoid confusing users (and potentially introducing yet another breaking change), I've added a function that converts the common query string args into the format supported by the modernc package. Most users would not need to worry about it, as wery few should change the DB connection string. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
OVERLORD added the pull-request label 2025-10-07 00:21:42 +03:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/pocket-id#748