Skip to content

feat(sqlite): add SQLite database engine support#156

Merged
usernane merged 13 commits into
mainfrom
dev
May 27, 2026
Merged

feat(sqlite): add SQLite database engine support#156
usernane merged 13 commits into
mainfrom
dev

Conversation

@usernane

Copy link
Copy Markdown
Member

Summary

Add complete SQLite database engine support using the native PHP sqlite3 extension, following the existing MySQL/MSSQL driver pattern.

Motivation

SQLite is widely used for local development, testing, embedded applications, and lightweight deployments. Adding SQLite support enables running the full test suite without external database servers (using :memory: databases), improving CI speed and contributor onboarding.

Closes #141

Changes

  • SQLiteConnection — native sqlite3 extension, :memory: and file-based support, WAL journal mode, FK enforcement, prepared statements with typed binding
  • SQLiteQuery — query builder with LIMIT/OFFSET, INSERT, UPDATE, DELETE, ALTER TABLE ADD/RENAME COLUMN, unsupported operations throw clear exceptions
  • SQLiteColumn — type affinity mapping (INTEGER, REAL, TEXT, BLOB), double-quote identifier quoting, AUTOINCREMENT support
  • SQLiteTable — DDL generation with CREATE TABLE IF NOT EXISTS, composite PRIMARY KEY, FOREIGN KEY, UNIQUE constraints
  • SQLiteInsertBuilder — positional parameter binding
  • ConnectionInfo — accepts sqlite type (host/port/user/password ignored)
  • ConnectionPool — dispatches SQLiteConnection
  • Database — dispatches SQLiteQuery and SQLiteTable
  • TableFactory / ColumnFactory — create SQLite instances, map identity to autoincrement
  • DataType — registers SQLite affinity types
  • TypesMap — bidirectional type mappings (SQLite ↔ MySQL, SQLite ↔ MSSQL)
  • README.md — updated supported databases and examples list
  • examples/17-sqlite/ — complete working example with CRUD, pagination, transactions, file-based DB

UI Changes

N/A

How to Test / Verify

# SQLite tests (no external DB needed)
php vendor/bin/phpunit -c tests/phpunit10.xml --testsuite "SQLite Tests"

# Run the example
php examples/17-sqlite/example.php

85 SQLite tests pass. Coverage: SQLiteColumn 100%, SQLiteQuery 100%, SQLiteTable 100%, SQLiteInsertBuilder 100%, SQLiteConnection 97%.

Breaking Changes and Migration Steps

None. This is a purely additive feature. No existing APIs were modified.

Checklist

  • I reviewed my own diff before requesting review
  • My commits follow Conventional Commits
  • I added/updated tests (or explained why not)
  • I updated docs (if needed) Docs Repo
  • I ran lint/cs-fixer (if applicable) (composer fix-cs)
  • I considered backward compatibility
  • I considered security

Related issues

Closes #141

Ibrahim BinAlshikh added 10 commits May 27, 2026 01:25
Add complete SQLite driver following the existing MySQL/MSSQL pattern:

- SQLiteConnection: native sqlite3 extension, :memory: support, WAL mode,
  foreign key enforcement, prepared statement execution
- SQLiteQuery: query builder with LIMIT/OFFSET, INSERT, UPDATE, DELETE,
  ALTER TABLE ADD COLUMN, RENAME COLUMN
- SQLiteColumn: type affinity mapping (INTEGER, REAL, TEXT, BLOB),
  double-quote identifier quoting, AUTOINCREMENT support
- SQLiteTable: DDL generation with CREATE TABLE IF NOT EXISTS,
  PRIMARY KEY, FOREIGN KEY, UNIQUE constraints
- SQLiteInsertBuilder: positional parameter binding

Integration points updated:
- ConnectionInfo: accept 'sqlite' type
- ConnectionPool: dispatch SQLiteConnection
- Database: dispatch SQLiteQuery and SQLiteTable
- TableFactory/ColumnFactory: create SQLite instances
- DataType: register SQLite affinity types

Refs: #141
…ping

- Add setAutoUpdate/isAutoUpdate no-ops to SQLiteColumn for ColumnFactory compatibility
- Handle auto-inc option for SQLite in ColumnFactory::primaryCheck
- Map MSSQL 'identity' option to SQLite autoincrement in ColumnFactory::identityCheck
- Update ConnectionInfoExtendedTest to expect 3 supported databases
Add bidirectional type mappings between SQLite and MySQL/MSSQL:
- mysql→sqlite: int→integer, varchar→text, decimal→real, blob→blob, etc.
- mssql→sqlite: nvarchar→text, money→real, bigint→integer, etc.
- sqlite→mysql: integer→int, real→decimal, text→text, blob→blob
- sqlite→mssql: integer→int, real→decimal, text→nvarchar, blob→varbinary

Enables cross-engine table migration via TableFactory::map().

Refs: #141
- SQLiteColumnTest: 100% coverage - type mapping, quoting, asString, cleanValue
- SQLiteTableTest: 100% coverage - DDL generation, PK, FK, unique, defaults
- SQLiteQueryTest: 98% coverage - SELECT, INSERT, UPDATE, DELETE, LIMIT/OFFSET,
  ADD COLUMN, RENAME COLUMN, bindings, unsupported operations
- SQLiteConnectionTest: 88% coverage - CRUD integration, transactions, rollback,
  connection lifecycle, constraint violations, error handling
- SQLiteInsertBuilder: 100% coverage

Overall SQLite coverage: 96% lines across all 5 classes.
Remaining uncovered: connection error paths requiring DB corruption.

Refs: #141
…5 classes

- Remove unreachable catch block in connect() (SQLite3 throws directly)
- Remove unreachable false-checks in runDirect/runPrepared (exceptions enabled)
- Remove unreachable null-check in renameCol (getOldName never returns null)
- Remove unused mapType method from SQLiteTable

Coverage: SQLiteColumn 100%, SQLiteQuery 100%, SQLiteTable 100%,
SQLiteInsertBuilder 100%, SQLiteConnection 97% (isAlive catch + __destruct)
- Add examples/17-sqlite/ with full CRUD, pagination, transactions, file-based DB
- Update README.md: add SQLite to supported databases and examples list
- Fix binding accumulation bug: reset bindings after query execution
- Fix UPDATE SET clause: disable table prefix on column names in SET
- Fix renameCol test to use Database instance with schema

Refs: #141
@codecov

codecov Bot commented May 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.25301% with 28 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.53%. Comparing base (8fed32a) to head (d01e456).
⚠️ Report is 14 commits behind head on main.

Files with missing lines Patch % Lines
WebFiori/Database/MsSql/MSSQLConnection.php 33.33% 8 Missing ⚠️
WebFiori/Database/Sqlite/SQLiteConnection.php 91.83% 8 Missing ⚠️
WebFiori/Database/Factory/ColumnFactory.php 78.57% 6 Missing ⚠️
WebFiori/Database/Database.php 71.42% 2 Missing ⚠️
WebFiori/Database/Factory/TableFactory.php 75.00% 1 Missing ⚠️
WebFiori/Database/Sqlite/SQLiteColumn.php 98.61% 1 Missing ⚠️
WebFiori/Database/Sqlite/SQLiteQuery.php 98.27% 1 Missing ⚠️
WebFiori/Database/Sqlite/SQLiteTable.php 98.75% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main     #156      +/-   ##
============================================
+ Coverage     87.89%   88.53%   +0.63%     
- Complexity     2185     2325     +140     
============================================
  Files            54       59       +5     
  Lines          5427     5763     +336     
============================================
+ Hits           4770     5102     +332     
- Misses          657      661       +4     
Flag Coverage Δ
php-8.1 74.17% <16.78%> (-4.69%) ⬇️
php-8.2 73.94% <16.54%> (-4.69%) ⬇️
php-8.3 88.53% <95.32%> (+0.82%) ⬆️
php-8.4 88.53% <95.32%> (+0.82%) ⬆️
php-8.5 88.53% <95.32%> (+0.82%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

usernane and others added 3 commits May 27, 2026 02:57
…ustion

- Add tearDown with ConnectionPool::reset() to release connections between tests
- Remove testGetNameEmpty that triggered PHP warnings on empty column names
…tQuery

Extract shared binding logic (addBinding, getBindings, resetBinding,
setBindings) into AbstractQuery as default implementations. MySQL
overrides with its own typed-binding structure.

Reduces code duplication between SQLite and MSSQL query builders.
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
6.7% Duplication on New Code (required ≤ 6%)

See analysis details on SonarQube Cloud

@usernane usernane merged commit 120d2ba into main May 27, 2026
17 of 20 checks passed
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.

feat(sqlite): Add SQLite database engine support

1 participant