PHPackages                             phly/sqlite-resource - 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. phly/sqlite-resource

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

phly/sqlite-resource
====================

Library for persisting JSON resources in SQLite

114PHP

Since May 29Pushed 13y ago1 watchersCompare

[ Source](https://github.com/weierophinney/phlyql_resource)[ Packagist](https://packagist.org/packages/phly/sqlite-resource)[ RSS](/packages/phly-sqlite-resource/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (1)Used By (0)

Phly\\SqliteResource
====================

[](#phlysqliteresource)

This is a "toy" library designed to make it easy to prototype persistence for RESTful APIs. It essentially allows you to create a SQLite database with the following columns:

- **id**, which represents an identifier. This is autogenerated by the library, and will be a 32 character hexidecimal string (i.e. characters 0-9 and a-f).
- **data**, a JSON-encoded string representing a resource. This will always be returned as an associative array.

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

[](#installation)

The easiest way to install is via [Composer](http://getcomposer.org). Download the composer installer, and create a `composer.json` file as follows:

```
{
    "minimum-stability": "dev",
    "require": {
        "phly/sqlite-resource": "dev-master"
    }
}
```

Then run `composer install`.

Schema
------

[](#schema)

A schema is available in [schema.sqlite.sql](schema.sqlite.sql). Essentially:

```
CREATE TABLE IF NOT EXISTS collection (
    id CHARACTER(32) PRIMARY KEY,
    data BLOB NOT NULL
);
```

Alter it as you see fit to change the table name.

Initialization
--------------

[](#initialization)

In order to instantiate `Phly\SqliteResource\SqliteResource`, you will need an instance of PDO. Typical instantiation will look like this:

```
use PDO;
use Phly\SqliteResource\SqliteResource;

$pdo = new PDO('sqlite:/path/to/database.db');
$resource = new SqliteResource($pdo, 'table-name');
```

API
---

[](#api)

The API supports the following operations:

- **create(array $data)** - Inserts the resource into the database and returns it, with a new "id" key with the newly created identifier.
- **fetch($id)** - Fetches the resource with the given identifier. If no resource is found, an exception is thrown.
- **fetchAll($limit = null, $offset = null)** - Fetches all resources from the database, returning an array of arrays. If a limit is given, returns only the number of resources indicated; if an offset is given along with a limit, returns resources from that offset
- **patch($id, array $data)** - Merges the provided `$data` with the record that already exists in the database identified by `$id` and saves it. The merged resource is returned.
- **update($id, array $data)** - Replaces the resource identified by `$id` with the `$data`. Returns the resource.
- **delete($id)** - Deletes the resource identified by `$id`.

Caveats
-------

[](#caveats)

Do not use this in production. Use a document database, or a relational database with a real schema that maps to the fields in your resources.

LICENSE
=======

[](#license)

This module is licensed using the BSD 2-Clause License:

```
Copyright (c) 2013, Matthew Weier O'Phinney
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

- Redistributions of source code must retain the above copyright notice, this
  list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
  this list of conditions and the following disclaimer in the documentation
  and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

```

###  Health Score

20

—

LowBetter than 13% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/25943?v=4)[Matthew Weier O'Phinney](/maintainers/weierophinney)[@weierophinney](https://github.com/weierophinney)

---

Top Contributors

[![weierophinney](https://avatars.githubusercontent.com/u/25943?v=4)](https://github.com/weierophinney "weierophinney (7 commits)")

### Embed Badge

![Health badge](/badges/phly-sqlite-resource/health.svg)

```
[![Health](https://phpackages.com/badges/phly-sqlite-resource/health.svg)](https://phpackages.com/packages/phly-sqlite-resource)
```

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

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

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

8351.6M87](/packages/propel-propel1)[jfelder/oracledb

Oracle DB driver for Laravel

11518.4k](/packages/jfelder-oracledb)

PHPackages © 2026

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