PHPackages                             hanneskod/yaysondb - 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. hanneskod/yaysondb

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

hanneskod/yaysondb
==================

Flat file db storing data as json arrays

2.2.0(6y ago)51.9k11WTFPLPHPPHP ^7.0CI failing

Since Oct 16Pushed 5y ago1 watchersCompare

[ Source](https://github.com/hanneskod/yaysondb)[ Packagist](https://packagist.org/packages/hanneskod/yaysondb)[ Docs](https://github.com/hanneskod/yaysondb)[ RSS](/packages/hanneskod-yaysondb/feed)WikiDiscussions 2.0 Synced 1mo ago

READMEChangelogDependencies (2)Versions (9)Used By (1)

Yaysondb
========

[](#yaysondb)

[![Packagist Version](https://camo.githubusercontent.com/e51f3f0428243510286cbec15c2927423ec49c8b42d73bad17a88911dc755db2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f68616e6e65736b6f642f796179736f6e64622e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/hanneskod/yaysondb)[![Build Status](https://camo.githubusercontent.com/b253237b1ff618d69ba324e56f66e4152f17712991df60d3e58bc822eb539d3d/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f68616e6e65736b6f642f796179736f6e64622f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/hanneskod/yaysondb)[![Quality Score](https://camo.githubusercontent.com/261c3f7bdce8b921524057b4b162e3b83cb61473a1c599d35586118956800de3/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f68616e6e65736b6f642f796179736f6e64622e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/hanneskod/yaysondb)

Flat file db in pure php.

Why?
----

[](#why)

Partly as a learning exercise, partly since I needed a simple and PHP only DB for some cli scripts.

### Features

[](#features)

- [Powerfull searches using search documents](#the-search-document)
- Supports limits, ordering and custom filtering expressions
- Multiple filesystem support through [Flysystem](https://flysystem.thephpleague.com)
- [Simple transaction support](#transactions)
- [Validates that source has not been altered before writing](#concurrency-protection)
- Fast logging with the dedicated LogEngine

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

[](#installation)

```
composer require hanneskod/yaysondb
```

Usage
-----

[](#usage)

### Setup

[](#setup)

[`Yaysondb`](/src/Yaysondb.php) works as a handler for multiple collections.

```
use hanneskod\yaysondb\Yaysondb;
use hanneskod\yaysondb\Engine\FlysystemEngine;
use League\Flysystem\Filesystem;
use League\Flysystem\Adapter\Local;

$db = new Yaysondb([
    'table' => new FlysystemEngine(
        'data.json',
        new Filesystem(new Local('path-to-files'))
    )
]);
```

Access [`collection`](/src/CollectionInterface.php) through property or `collection()`

```
$db->table === $db->collection('table');
```

### Create

[](#create)

```
$db->table->insert(['name' => 'foobar']);
```

#### Transactions

[](#transactions)

Commit or rollback changes using `commit()`, `reset()` and `inTransaction()`

```
$db->table->commit();
```

#### Concurrency protection

[](#concurrency-protection)

Yaysondb supports limited concurrency protection when using the flysystem engine. A hash of the backend file is calculated at each read and any write action will fail if the hash has changed.

### Read

[](#read)

Create search documents using the [`Operators`](/src/Operators.php) class.

```
use hanneskod\yaysondb\Operators as y;

// Find all documents with an address in new york
$result = $db->table->find(
    y::doc([
        'address' => y::doc([
            'town' => y::regexp('/new york/i')
        ])
    ])
);

// The result set is filterable
foreach ($result->limit(2) as $id => $doc) {
    // iterate over the first 2 results
}
```

#### The search document

[](#the-search-document)

The following operators are available when creating search documents:

OperatorDescription`doc(array $query)`Evaluate documents and nested subdocuments`not(Expr $e)`Negate expression`exists()`Use to assert that a document key exists`type($type)`Check if operand is of php type`in(array $list)`Check if operand is included in list`regexp($reg)`Check if operand matches regular expression`equals($op)`Check if operands equals each other`same($op)`Check if operands are the same`greaterThan($op)`Check if supplied operand is greater than loaded operand`greaterThanOrEquals($op)`Check if supplied operand is greater than or equals loaded operand`lessThan($op)`Check if supplied operand is less than loaded operand`lessThanOrEquals($op)`Check if supplied operand is less than or equals loaded operand`all(Expr ...$e)`All contained expressions must evaluate to true`atLeastOne(Expr ...$e)`At least one contained expressions must evaluate to true`exactly($c, Expr ...$e)`Match exact number of contained expressions evaluating to true`none(Expr ...$e)`No contained expressions are allowed evaluate to true`one(Expr ...$ex)`Exactly one contained expressions must evaluate to true`listAll(Expr $e)`Expression must evaluate to true for each list item`listAtLeastOne(Expr $e)`Expression must evaluate to true for at least one list item`listExactly($c, Expr $e)`Expression must evaluate to true for exact numer of items in list`listNone(Expr $e)`Expression is not allowed to evaluate to true for any list item`listOne(Expr $e)`Expression must evaluate to true for exactly one list item### Update

[](#update)

`Collection::update()` takes two arguments. A search document and an array of values. Documents matching the search document are updated with the supplied values.

### Delete

[](#delete)

`Collection::delete()` takes a search document as sole argument. Documents matching the search document are removed.

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 97.3% 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

Every ~274 days

Recently: every ~284 days

Total

9

Last Release

2028d ago

Major Versions

1.0.x-dev → 2.0.02017-01-19

PHP version history (3 changes)1.0.0PHP &gt;=5.6

2.0.0PHP ^7.0

2.0.x-devPHP &gt;=7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/b0af6567c7f4f5518a422192675445464fdcf18acbc9459b3205da9fd446f8d0?d=identicon)[hanneskod](/maintainers/hanneskod)

---

Top Contributors

[![hanneskod](https://avatars.githubusercontent.com/u/1369274?v=4)](https://github.com/hanneskod "hanneskod (36 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")

---

Tags

jsondatabasenosqljsondb

### Embed Badge

![Health badge](/badges/hanneskod-yaysondb/health.svg)

```
[![Health](https://phpackages.com/badges/hanneskod-yaysondb/health.svg)](https://phpackages.com/packages/hanneskod-yaysondb)
```

###  Alternatives

[cubettech/lacassa

Cassandra based query builder for laravel.

358.5k](/packages/cubettech-lacassa)[soosyze/queryflatfile

The Queryflatfile is PHP library for simple database not SQL

181.0k1](/packages/soosyze-queryflatfile)

PHPackages © 2026

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