Skip to content

r4ndsen/sqlite-php

Repository files navigation

r4ndsen / sqlite-php

High-level helpers for SQLite3 with batteries-included query utilities, schema introspection, and pragma management.

Latest Stable Version Build Status Coverage Status

Requirements

  • PHP 8.2 or newer
  • ext-sqlite3 and ext-mbstring

Installation

Composer

composer require r4ndsen/sqlite-php

From source

git clone https://github.com/r4ndsen/sqlite-php.git
cd sqlite-php
composer install

Quick start

<?php

use r4ndsen\SQLite;
use r4ndsen\SQLite\Column;

$sqlite = new SQLite(':memory:');

$tasks = $sqlite->getTable('tasks');
$tasks
    ->addCreateColumn(Column::createIntegerColumn('id'))
    ->addCreateColumn(Column::createTextColumn('title')->disallowNull())
    ->addCreateColumn(Column::createIntegerColumn('is_done', 0))
    ->createIfNotExists();

$tasks->getDynamicInsertTable()
    ->push(['id' => 1, 'title' => 'Write docs'])
    ->push(['id' => 2, 'title' => 'Tag release', 'is_done' => 1])
    ->commit();

$openTasks = $sqlite->fetchPairs(
    'select id, title from tasks where is_done = :is_done order by id',
    ['is_done' => 0],
);
// [1 => 'Write docs']

foreach ($tasks as $row) {
    // Table implements IteratorAggregate, so you can iterate rows directly
}

$sqlite->validate(); // Runs PRAGMA integrity_check and throws on corruption

Head over to the documentation for more detail on tables, column helpers, pragmas, and query convenience methods.

Development tooling

All just recipes run from the project root (install just from https://github.com/casey/just):

just test        # PHPUnit against the current PHP version
just tests       # PHPUnit against the Docker matrix (PHP 8.2–8.5)
just coverage    # Generates HTML coverage and prints the report path
just infection   # Mutation testing (requires Xdebug)
just stan        # PHPStan static analysis

License

r4ndsen/sqlite-php is licensed under the MIT License. See LICENSE for details.

Changelog

See CHANGELOG for release notes.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors