- What is hyperf/database-sqlite used for?
- It provides the SQLite driver, connection handling, and query builder integration needed to run SQLite through Hyperf's database component. You use it when you want a simple file-based or in-memory database instead of a client-server engine like MySQL or PostgreSQL. Typical cases are small services, CLI tools, local development, and automated tests.
- How do I install hyperf/database-sqlite?
- Install it with Composer by running composer require hyperf/database-sqlite in your Hyperf application. Make sure the PDO SQLite extension is enabled in your PHP build, since the driver relies on it. After installation, add a sqlite connection to your database configuration.
- How do I configure a SQLite connection in Hyperf?
- Add an entry to config/autoload/databases.php with driver set to sqlite and database pointing to your file path, for example BASE_PATH . '/runtime/database.sqlite'. You can also read the path from an environment variable so local and production setups differ cleanly. The connection is then resolved through the standard Hyperf Db facade or injected DbInterface.
- Can I use hyperf/database-sqlite in a Laravel application?
- No. This package is built for Hyperf's coroutine-based framework, not Laravel; Laravel already ships SQLite support through its own database layer. The query builder API feels familiar because Hyperf's database component follows the same conventions, but the container, configuration, and lifecycle are Hyperf-specific. Use it only in Hyperf projects.
- Does it support in-memory SQLite for testing?
- Yes, you can point database at :memory: to get a fast, disposable database for tests. Keep in mind that an in-memory database lives only as long as its connection, so pooled or multiple connections each see their own empty database. For tests that need shared state across connections, use a temporary file path instead.
- Which query builder features are available with SQLite?
- You get the standard fluent builder: selects, joins, where clauses, aggregates, inserts, updates, deletes, and transactions. Coverage follows what SQLite itself supports, so features such as right joins or certain ALTER TABLE operations are limited by the engine. Raw expressions remain available when you need something SQLite-specific.
- How do I create the SQLite database file and run migrations?
- Create an empty file at the configured path, or let SQLite create it on first write if the directory is writable. Then use Hyperf's migration component to generate and run schema migrations as usual. Ensure the runtime directory exists and is writable by the process user before running migrations.
- Does it work with Swoole connection pooling and coroutines?
- Yes, the connection is resolved through Hyperf's database manager, so it participates in the usual pool configuration. Because SQLite allows only one writer at a time, heavy concurrent writes will serialize or raise busy errors. Enable WAL mode and keep write transactions short when you expect concurrency.
- Is hyperf/database-sqlite suitable for production?
- It is fine for read-heavy or low-write services, embedded persistence, and single-node deployments where a file database is acceptable. Watch out for write lock contention, file permissions, and the fact that the database file must be backed up and stored on reliable local disk. For high write throughput or multi-node setups, a client-server database is usually the better choice.
- What are the alternatives to hyperf/database-sqlite?
- The main alternatives are Hyperf's MySQL and PostgreSQL drivers, which use the same database component and query builder API. If you only need key-value style persistence, Hyperf's cache or a dedicated storage library may be simpler. Check the package's composer.json for its supported Hyperf and PHP version constraints before upgrading.