PHPackages                             korriganmaster/lite-collection - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. korriganmaster/lite-collection

ActiveLibrary[Database &amp; ORM](/categories/database)

korriganmaster/lite-collection
==============================

PHP SQLlite collection

v1.0.0(6mo ago)04MITPHPPHP &gt;=8.0

Since Dec 22Pushed 5mo agoCompare

[ Source](https://github.com/KorriganMaster/lite-collection)[ Packagist](https://packagist.org/packages/korriganmaster/lite-collection)[ RSS](/packages/korriganmaster-lite-collection/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (3)Versions (4)Used By (0)

LiteCollection
==============

[](#litecollection)

A lightweight PHP library for managing data collections with a persistent storage system using SQLite.

Features
--------

[](#features)

- **Lightweight Collection**: Implements `Countable`, `ArrayAccess`, and `IteratorAggregate` interfaces
- **SQLite Storage**: Data persistence in memory or on disk
- **Two Operating Modes**:
    - `MODE_NORMAL`: Uses auto-incremented keys (0, 1, 2...)
    - `MODE_ASSOCIATIVE`: Uses a custom primary key
- **Simple Interface**: Manipulate data like a standard PHP array

Installation
------------

[](#installation)

```
composer require korriganmaster/lite-collection
```

Usage
-----

[](#usage)

### Basic Example

[](#basic-example)

```
use Korriganmaster\LiteCollection\LiteCollection;
use Korriganmaster\LiteCollection\Storage\SqliteStorage;

// Create in-memory storage
$storage = new SqliteStorage();
$collection = new LiteCollection($storage);

// Add items
$collection[] = ['id' => 1, 'name' => 'Item 1'];
$collection[] = ['id' => 2, 'name' => 'Item 2'];

// Access items
echo $collection[0]['name']; // "Item 1"

// Count items
echo count($collection); // 2

// Iterate over the collection
foreach ($collection as $item) {
    echo $item['name'];
}
```

### Associative Mode with Custom Key

[](#associative-mode-with-custom-key)

```
use Korriganmaster\LiteCollection\Storage\SqliteStorage;
use Korriganmaster\LiteCollection\Storage\StorageInterface;

// Create storage with a custom primary key
$storage = new SqliteStorage(
    StorageInterface::MODE_ASSOCIATIVE,
    'custom_id'
);

$storage->insert(['custom_id' => 100, 'name' => 'Item 100']);

// Access by custom key
$item = $storage->findById(100);
```

### Persistent Disk Storage

[](#persistent-disk-storage)

```
// Create disk storage
$storage = new SqliteStorage(
    StorageInterface::MODE_NORMAL,
    'id',
    'path/to/database.sqlite'
);
```

API
---

[](#api)

### LiteCollection

[](#litecollection-1)

The [`LiteCollection`](src/LiteCollection.php) class provides a collection interface:

- **`count(): int`**: Returns the number of items
- **`offsetGet($offset): mixed`**: Retrieves an item by its index
- **`offsetSet($offset, $value): void`**: Sets or updates an item
- **`offsetUnset($offset): void`**: Removes an item
- **`offsetExists($offset): bool`**: Checks if an item exists
- **`getIterator(): Traversable`**: Returns an iterator to traverse the collection

### SqliteStorage

[](#sqlitestorage)

The [`SqliteStorage`](src/Storage/SqliteStorage.php) class implements [`StorageInterface`](src/Storage/StorageInterface.php):

- **`insert(mixed $item): void`**: Inserts a new item
- **`findById(int $id): mixed`**: Finds an item by its ID
- **`exists(int $id): bool`**: Checks if an item exists
- **`update(int $id, mixed $item): void`**: Updates an existing item
- **`delete(int $id): void`**: Deletes an item
- **`count(): int`**: Returns the number of items
- Implements `Iterator` to traverse items

### StorageInterface

[](#storageinterface)

The [`StorageInterface`](src/Storage/StorageInterface.php) interface defines the contract for storage systems:

**Storage Modes:**

- `StorageInterface::MODE_NORMAL`: Normal mode with auto-incremented keys
- `StorageInterface::MODE_ASSOCIATIVE`: Associative mode with custom primary key

Testing
-------

[](#testing)

The project includes unit tests using PHPUnit:

```
composer test
```

Tests cover:

- [`LiteCollectionTest`](test/LiteCollectionTest.php): Collection tests
- [`SqliteStorageTest`](test/SqliteStorageTest.php): SQLite storage tests

Development
-----------

[](#development)

### Requirements

[](#requirements)

- PHP 8.0 or higher
- SQLite3 extension
- Composer

### Development Tools

[](#development-tools)

```
# Run tests
vendor/bin/phpunit

# Static analysis
vendor/bin/phpstan analyse

# Code style fixing
vendor/bin/php-cs-fixer fix
```

Architecture
------------

[](#architecture)

The project follows a simple architecture:

- **[`LiteCollection`](src/LiteCollection.php)**: Main collection class
- **[`AbstractStorage`](src/Storage/AbstractStorage.php)**: Abstract class for storage systems
- **[`SqliteStorage`](src/Storage/SqliteStorage.php)**: SQLite storage implementation
- **[`StorageInterface`](src/Storage/StorageInterface.php)**: Interface defining the storage contract

License
-------

[](#license)

This project is licensed under the MIT License.

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance69

Regular maintenance activity

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

193d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1027951?v=4)[KorriganMaster](/maintainers/KorriganMaster)[@KorriganMaster](https://github.com/KorriganMaster)

---

Top Contributors

[![KorriganMaster](https://avatars.githubusercontent.com/u/1027951?v=4)](https://github.com/KorriganMaster "KorriganMaster (19 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/korriganmaster-lite-collection/health.svg)

```
[![Health](https://phpackages.com/badges/korriganmaster-lite-collection/health.svg)](https://phpackages.com/packages/korriganmaster-lite-collection)
```

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k117.2M118](/packages/jdorn-sql-formatter)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M87](/packages/propel-propel1)[pgvector/pgvector

pgvector support for PHP

198741.5k12](/packages/pgvector-pgvector)[jfelder/oracledb

Oracle DB driver for Laravel

11518.4k](/packages/jfelder-oracledb)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
