phpnomad/sqlite-integration implements phpnomad/db's query builders and table strategies for SQLite via PDO. It opens its own connection (configured by DSN), generates SQLite-flavored SQL, and exposes the same strategy interfaces that phpnomad/mysql-integration does — so entity classes, repositories, and validation are portable between MySQL and SQLite.
The intended use case is the local-storage half of a desktop app whose server uses phpnomad/mysql-integration. Same models on both sides, only the strategy binding differs.
composer require phpnomad/sqlite-integration- A
QueryBuilderandClauseBuilderthat emit SQLite-flavored SQL for SELECT, JOIN, GROUP BY, ORDER BY, LIMIT, OFFSET, and the full set of comparison operators (including IS NULL, IN, BETWEEN, and AND/OR groups) QueryStrategy,TableCreateStrategy,TableDeleteStrategy,TableExistsStrategy, andTableUpdateStrategyimplementations covering insert, update, delete, query, estimated count, and schema managementTableUpdateStrategy::syncColumnshandles SQLite's limited ALTER — simple ADD/DROP COLUMN for the common case, transactional create-copy-drop-rename for affinity changesPdoDatabaseStrategy— a PDO-backedDatabaseStrategythat parses SafeMySQL-style placeholders (?n,?s,?i,?d,?a) so the builders speak the same language as the MySQL pipelineConnection— a thin PDO wrapper that turns on foreign keys and WAL journaling by defaultDatabaseDateAdapterthat round-tripsDateTimethrough the sameY-m-d H:i:sformat the MySQL adapter uses- A
Databasefacade exposingparse(),query(), andlastInsertId()for the boundDatabaseStrategy
- PHP 8.3+ with
pdoandpdo_sqliteextensions phpnomad/dbphpnomad/loader ^1.0 || ^2.0
This package supplies its own DatabaseStrategy (PdoDatabaseStrategy) — unlike phpnomad/mysql-integration, you do not need a separate driver package.
Add Initializer to your bootstrapper. The integration registers every builder, strategy, and adapter listed above.
<?php
use PHPNomad\Di\Container\Container;
use PHPNomad\Loader\Bootstrapper;
use PHPNomad\SQLite\Integration\Initializer as SQLiteIntegration;
$container = new Container();
$bootstrapper = new Bootstrapper(
$container,
new SQLiteIntegration()
);
$bootstrapper->load();By default the integration opens an in-memory database. Point it at a file by setting PHPNOMAD_SQLITE_DSN:
PHPNOMAD_SQLITE_DSN="sqlite:/var/lib/myapp/data.db" php bin/...Handlers in phpnomad/db will then resolve QueryStrategy, QueryBuilder, ClauseBuilder, and the table strategies from this package.
The strategy layer is dialect-aware; everything above it is not. A few practical differences to know about:
- No
AUTO_INCREMENTkeyword. UseINTEGER PRIMARY KEY(rowid alias) or passAUTOINCREMENTas a column attribute for strictly-monotonic ids. The MySQLAUTO_INCREMENTattribute is translated automatically. - Type affinity, not types.
VARCHAR(255)andTEXTare the same thing in SQLite. MySQL types (BIGINT,LONGTEXT,DATETIME,BOOLEAN, etc.) are mapped to SQLite-canonical equivalents inCREATE TABLE. - Limited
ALTER TABLE. Adding and dropping columns work directly. Changing a column's type affinity triggers a transactional rebuild handled byTableUpdateStrategy. LIKEis case-insensitive by default for ASCII. SetPRAGMA case_sensitive_like = 1if your app needs MySQL-like behavior.- No
ENGINE=InnoDB/CHARACTER SET=table options. Silently dropped.
composer install
./vendor/bin/phpunitThe test suite covers placeholder semantics, query construction, clause composition, table lifecycle, schema migration, value safety against SQL injection, type translation, and full-stack scenarios.
The phpnomad/db documentation at phpnomad.com covers table schemas, handlers, and how the query building pipeline fits together.
MIT License. See LICENSE.txt.