go-sqlite3 icon indicating copy to clipboard operation
go-sqlite3 copied to clipboard

Add driver.Connector implementation for SQLite (#1001)

Open ljluestc opened this issue 5 months ago • 0 comments

Summary of Changes

This pull request implements the database/sql/driver.Connector interface for go-sqlite3 by adding a SQLiteConnector struct and a NewConnector method, addressing issue #1001. The implementation enables configuring SQLite connections without global driver registration via sql.Register, simplifying application and test setups by avoiding driver name conflicts. It supports context-aware connections and custom DSN options (e.g., _journal_mode, _busy_timeout), aligning with Go 1.10+ practices. Additionally, this PR corrects unintended file mode changes for sqlite3.go and sqlite3_test.go from 100755 (executable) to 100644 (non-executable) that occurred in the initial commit. Tests verify connector functionality, and documentation has been updated.

Key Changes

  • Added SQLiteConnector in sqlite3.go:

    • Implements driver.Connector with Connect and Driver methods.
    • Added NewConnector method to SQLiteDriver for creating connectors.
    • Supports context cancellation and DSN options via Options map.
  • Added tests in sqlite3_connector_test.go:

    • Verifies NewConnector, Connect, and basic database operations (create, insert, select).
    • Tests context cancellation and custom options (e.g., _journal_mode=WAL).
    • Confirms Driver method returns the correct SQLiteDriver.
  • Updated existing tests in sqlite3_test.go:

    • Replaced sql.Open with sql.OpenDB using SQLiteConnector where possible to avoid global driver registration.
  • Fixed file modes:

    • Restored sqlite3.go and sqlite3_test.go to 100644 (non-executable) to correct unintended executable mode (100755).

ljluestc avatar Jun 28 '25 04:06 ljluestc